diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..acc2150 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM node:10-alpine +WORKDIR /app +COPY My-First . +RUN npm install +CMD ["npm", "start"] +EXPOSE 3000 diff --git a/My-First/package.json b/My-First/package.json index 2771f48..263bac6 100644 --- a/My-First/package.json +++ b/My-First/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "scripts": { "ng": "ng", - "start": "ng serve", + "start": "ng serve --host 0.0.0.0", "build": "ng build", "test": "ng test", "lint": "ng lint", diff --git a/My-First/src/app/create-publication.jsx b/My-First/src/app/create-publication.jsx new file mode 100644 index 0000000..9920d72 --- /dev/null +++ b/My-First/src/app/create-publication.jsx @@ -0,0 +1,325 @@ +import { + Alert, + Button, + CircularProgress, + Collapse, + FormControl, + Input, + InputLabel, + Stack, + Typography, + LinearProgress, +} from '@mui/material'; +import fileSize from 'filesize'; +import { useFormik } from 'formik'; +import { useRouter } from 'next/router'; +import { useContext, useState } from 'react'; +import FeaturedIcon from '../../components/common/icon/FeaturedIcon'; +import AuthLayout from '../../components/common/layout/AuthLayout'; +import { File, UploadCloud } from '../../res/icons/icons'; +import api from '../../lib/utils/axios/auth'; +import { SessionContext } from '../../lib/context/PublishedSession'; + +const humanReadableSize = fileSize.partial(); + +const CreatePublication = () => { + // const {data: session, status} = useSession() + const [logo, setLogo] = useState(null); + const [error, setError] = useState(null); + const [isLoading, setIsLoading] = useState(false); + const [fileUploadProgress, setFileUploadProgress] = useState(0); + const router = useRouter(); + const { status, publication } = useContext(SessionContext); + // console.log(cValue) + + // console.log(session) + + const createPublication = (values) => { + setIsLoading(true); + const payload = { + ...values, + logo: logo, + }; + console.log('payload', payload); + api.publication + .create(payload, { + headers: { 'Content-Type': 'multipart/form-data' }, + onUploadProgress: (progressEvent) => { + if (progressEvent.lengthComputable) { + let currentProgress = (progressEvent.loaded / progressEvent.total) * 100; + setFileUploadProgress(currentProgress); + } + }, + }) + .then((data) => { + console.log(data); + router.replace(`https://${data.subdomain}.${process.env.DOMAIN}`); + }) + .catch((err) => { + console.log('error', err); + setError(Object.values(err)[0]); + }) + .finally(() => { + setIsLoading(false); + }); + }; + + const formik = useFormik({ + initialValues: { + name: '', + description: '', + subdomain: '', + }, + onSubmit: createPublication, + }); + + const handleLogo = (e) => { + const file = e.target.files[0]; + console.log('file', file); + setLogo(file); + }; + + if (status !== 'unauthenticated') + return ( + + + Authentication required + + + + + + + ); + + if (publication) + return ( + + You already have a publication + + ); + + return ( + + + Create Publication + + + {error} + + + + + Publication logo + + + + + {logo && ( + + + + + + {logo.name} + + {/* { fileUploadState==='success' && } */} + + + {humanReadableSize(logo.size)} + + + + {fileUploadProgress > 0 ? fileUploadProgress + '%' : ''} + + + + )} + + + + Publication name + + + + + + + + Description + + + + + + + + Website + + + + .onpublished.com + + } + /> + + + + ); +}; + +CreatePublication.getLayout = function getLayout(page) { + return {page}; +}; + +export default CreatePublication; diff --git a/My-First/src/app/signin.jsx b/My-First/src/app/signin.jsx new file mode 100644 index 0000000..b4e9f5c --- /dev/null +++ b/My-First/src/app/signin.jsx @@ -0,0 +1,203 @@ +import { + Box, + Button, + CircularProgress, + FormControl, + InputLabel, + Input, + Stack, + SvgIcon, + TextField, + Typography, +} from '@mui/material'; +import { useFormik } from 'formik'; +import Link from 'next/link'; +import DefaultIcon from '../../components/common/icon/DefaultIcon'; +import { ArrowLeft, ArrowLeftIcon, Home } from '../../res/icons/icons'; +import { signIn, signOut, useSession } from 'next-auth/react'; +import { useRouter } from 'next/router'; +import { useContext, useEffect, useState } from 'react'; +import PasswordInput from '../../components/common/inputfields/PasswordInput'; +import AuthLayout from '../../components/common/layout/AuthLayout'; +import { SessionContext } from '../../lib/context/PublishedSession'; + +const SignIn = () => { + const router = useRouter(); + const [error, setError] = useState(); + const [isLoading, setIsLoading] = useState(false); + const { signIn, user, publication, signOut } = useContext(SessionContext); + + // useEffect(() => { + // if(publication) { + // router.replace(publication.redirect_url) + // } + // if(!publication && user) { + // router.replace('/posts') + // } + // }, [user, publication]) + + const handleSignIn = async (values) => { + setIsLoading(true); + signIn({ + email: values.email, + password: values.password, + }) + .then((res) => { + console.log('signin', res); + if (res.subdomain) router.replace('http://' + res.subdomain + '.' + process.env.NEXT_PUBLIC_DOMAIN + '/posts'); + else router.replace('/creator/create-publication'); + }) + .finally(() => { + setIsLoading(false); + }); + }; + + const handleSignOut = async () => { + console.log('Sign out'); + const res = await signOut({ + redirect: false, + }); + console.log(res); + }; + + const formik = useFormik({ + initialValues: { + email: '', + password: '', + }, + onSubmit: handleSignIn, + }); + + if (publication) + return ( + + + You{"'"}re signed in as {publication.name} + + + + + ); + + return ( + + + + + + + + Welcome Back + + + Sign in to continue + + + + + + + + + + Forgot password? + + + + + + New to Published? + + + + + ); +}; + +SignIn.getLayout = function getLayout(page) { + return {page}; +}; + +export default SignIn;