From 4e967c5720d7ec8115eb5b294176bd98fc7f59bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=B1dvan=20Akca?= Date: Thu, 2 Mar 2023 16:42:50 +0300 Subject: [PATCH 1/7] feat: add signup link to login and create signup dummy page --- .../web/src/components/LoginForm/index.tsx | 7 ++ .../web/src/components/LoginForm/style.ee.ts | 7 ++ .../src/components/SignUpForm/index.ee.tsx | 103 ++++++++++++++++++ packages/web/src/config/urls.ts | 1 + packages/web/src/pages/SignUp/index.ee.tsx | 14 +++ packages/web/src/routes.tsx | 10 ++ 6 files changed, 142 insertions(+) create mode 100644 packages/web/src/components/LoginForm/style.ee.ts create mode 100644 packages/web/src/components/SignUpForm/index.ee.tsx create mode 100644 packages/web/src/pages/SignUp/index.ee.tsx diff --git a/packages/web/src/components/LoginForm/index.tsx b/packages/web/src/components/LoginForm/index.tsx index 1fec7ab2..64759980 100644 --- a/packages/web/src/components/LoginForm/index.tsx +++ b/packages/web/src/components/LoginForm/index.tsx @@ -10,6 +10,7 @@ import * as URLS from 'config/urls'; import { LOGIN } from 'graphql/mutations/login'; import Form from 'components/Form'; import TextField from 'components/TextField'; +import { Link } from './style.ee'; function renderFields(props: { loading: boolean }) { const { loading = false } = props; @@ -49,6 +50,12 @@ function renderFields(props: { loading: boolean }) { > Login + + + + Don't have an Automatisch account yet? + Sign Up + ); }; diff --git a/packages/web/src/components/LoginForm/style.ee.ts b/packages/web/src/components/LoginForm/style.ee.ts new file mode 100644 index 00000000..a49e5c6e --- /dev/null +++ b/packages/web/src/components/LoginForm/style.ee.ts @@ -0,0 +1,7 @@ +import { styled } from '@mui/material/styles'; +import { Link as RouterLink } from 'react-router-dom'; + +export const Link = styled(RouterLink)(({theme}) => ({ + textDecoration: 'underline', + marginLeft: theme.spacing(0.5) +})); \ No newline at end of file diff --git a/packages/web/src/components/SignUpForm/index.ee.tsx b/packages/web/src/components/SignUpForm/index.ee.tsx new file mode 100644 index 00000000..d3ecfd6d --- /dev/null +++ b/packages/web/src/components/SignUpForm/index.ee.tsx @@ -0,0 +1,103 @@ +import * as React from 'react'; +import { useNavigate } from 'react-router-dom'; +import { useMutation } from '@apollo/client'; +import Paper from '@mui/material/Paper'; +import Typography from '@mui/material/Typography'; +import LoadingButton from '@mui/lab/LoadingButton'; + +import useAuthentication from 'hooks/useAuthentication'; +import * as URLS from 'config/urls'; +import { LOGIN } from 'graphql/mutations/login'; +import Form from 'components/Form'; +import TextField from 'components/TextField'; + +function renderFields(props: { loading: boolean }) { + const { loading = false } = props; + + return () => { + return ( + <> + + + + + + Login + + + ); + }; +} + +function SignUpForm() { + const navigate = useNavigate(); + const authentication = useAuthentication(); + const [login, { loading }] = useMutation(LOGIN); + + React.useEffect(() => { + if (authentication.isAuthenticated) { + navigate(URLS.DASHBOARD); + } + }, [authentication.isAuthenticated]); + + const handleSubmit = async (values: any) => { + const { data } = await login({ + variables: { + input: values, + }, + }); + + const { token } = data.login; + + authentication.updateToken(token); + }; + + const render = React.useMemo(() => renderFields({ loading }), [loading]); + + return ( + + theme.palette.text.disabled, + pb: 2, + mb: 2, + }} + gutterBottom + > + Login + + +
+ + ); +} + +export default SignUpForm; diff --git a/packages/web/src/config/urls.ts b/packages/web/src/config/urls.ts index aeca5e82..062d88f4 100644 --- a/packages/web/src/config/urls.ts +++ b/packages/web/src/config/urls.ts @@ -5,6 +5,7 @@ export const EXECUTION = (executionId: string): string => `/executions/${executionId}`; export const LOGIN = '/login'; +export const SIGNUP = '/sign-up'; export const APPS = '/apps'; export const NEW_APP_CONNECTION = '/apps/new'; diff --git a/packages/web/src/pages/SignUp/index.ee.tsx b/packages/web/src/pages/SignUp/index.ee.tsx new file mode 100644 index 00000000..afe51ddb --- /dev/null +++ b/packages/web/src/pages/SignUp/index.ee.tsx @@ -0,0 +1,14 @@ +import * as React from 'react'; +import Box from '@mui/material/Box'; +import Container from 'components/Container'; +import SignUpForm from 'components/SignUpForm/index.ee'; + +export default function Login(): React.ReactElement { + return ( + + + + + + ); +} diff --git a/packages/web/src/routes.tsx b/packages/web/src/routes.tsx index a78b64af..5120663c 100644 --- a/packages/web/src/routes.tsx +++ b/packages/web/src/routes.tsx @@ -8,6 +8,7 @@ import Execution from 'pages/Execution'; import Flows from 'pages/Flows'; import Flow from 'pages/Flow'; import Login from 'pages/Login'; +import SignUp from 'pages/SignUp/index.ee'; import EditorRoutes from 'pages/Editor/routes'; import * as URLS from 'config/urls'; import settingsRoutes from './settingsRoutes'; @@ -80,6 +81,15 @@ export default ( } /> + + + + } + /> + Date: Fri, 3 Mar 2023 11:34:53 +0300 Subject: [PATCH 2/7] feat: create signup form --- .../src/components/SignUpForm/index.ee.tsx | 126 ++++++++++++------ 1 file changed, 82 insertions(+), 44 deletions(-) diff --git a/packages/web/src/components/SignUpForm/index.ee.tsx b/packages/web/src/components/SignUpForm/index.ee.tsx index d3ecfd6d..1f95ee08 100644 --- a/packages/web/src/components/SignUpForm/index.ee.tsx +++ b/packages/web/src/components/SignUpForm/index.ee.tsx @@ -4,55 +4,31 @@ import { useMutation } from '@apollo/client'; import Paper from '@mui/material/Paper'; import Typography from '@mui/material/Typography'; import LoadingButton from '@mui/lab/LoadingButton'; +import * as yup from 'yup'; import useAuthentication from 'hooks/useAuthentication'; import * as URLS from 'config/urls'; import { LOGIN } from 'graphql/mutations/login'; import Form from 'components/Form'; import TextField from 'components/TextField'; +import { yupResolver } from '@hookform/resolvers/yup'; -function renderFields(props: { loading: boolean }) { - const { loading = false } = props; +const validationSchema = yup.object().shape({ + fullName: yup.string().required(), + email: yup.string().email().required(), + password: yup.string().required(), + confirmPassword: yup + .string() + .required() + .oneOf([yup.ref('password')], 'Passwords must match'), +}); - return () => { - return ( - <> - - - - - - Login - - - ); - }; -} +const initialValue = { + fullName: '', + email: '', + password: '', + confirmPassword: '', +}; function SignUpForm() { const navigate = useNavigate(); @@ -77,7 +53,7 @@ function SignUpForm() { authentication.updateToken(token); }; - const render = React.useMemo(() => renderFields({ loading }), [loading]); + //const render = React.useMemo(() => renderFields({ loading }), [loading]); return ( @@ -92,10 +68,72 @@ function SignUpForm() { }} gutterBottom > - Login + Sign Up - + ( + <> + + + + + + + + + + Sign Up + + + )} + /> ); } From 18089a80762390f9c68b8cac05220318e6b65e44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=B1dvan=20Akca?= Date: Fri, 3 Mar 2023 14:04:23 +0300 Subject: [PATCH 3/7] feat: add signup logic --- packages/backend/src/graphql/mutations/create-user.ee.ts | 4 +++- packages/backend/src/graphql/schema.graphql | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/graphql/mutations/create-user.ee.ts b/packages/backend/src/graphql/mutations/create-user.ee.ts index 804daf00..4a92faa6 100644 --- a/packages/backend/src/graphql/mutations/create-user.ee.ts +++ b/packages/backend/src/graphql/mutations/create-user.ee.ts @@ -4,11 +4,12 @@ type Params = { input: { email: string; password: string; + fullName: string; }; }; const createUser = async (_parent: unknown, params: Params) => { - const { email, password } = params.input; + const { email, password, fullName } = params.input; const existingUser = await User.query().findOne({ email }); @@ -19,6 +20,7 @@ const createUser = async (_parent: unknown, params: Params) => { const user = await User.query().insert({ email, password, + fullName, role: 'user', }); diff --git a/packages/backend/src/graphql/schema.graphql b/packages/backend/src/graphql/schema.graphql index 1e09a90e..76bf8310 100644 --- a/packages/backend/src/graphql/schema.graphql +++ b/packages/backend/src/graphql/schema.graphql @@ -335,6 +335,7 @@ input DeleteStepInput { } input CreateUserInput { + fullName: String! email: String! password: String! } @@ -428,6 +429,7 @@ input StepInput { type User { id: String fullName: String + password: String email: String role: String createdAt: String From d061eb7b588687aa54ee11192d6a094cc7c8f9a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=B1dvan=20Akca?= Date: Fri, 3 Mar 2023 14:10:54 +0300 Subject: [PATCH 4/7] feat: update migration logic and remove consolelog --- packages/web/src/components/LoginForm/index.tsx | 5 ++--- .../web/src/components/SignUpForm/index.ee.tsx | 15 +++++++++++---- .../web/src/graphql/mutations/create-user.ee.ts | 10 ++++++++++ 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 packages/web/src/graphql/mutations/create-user.ee.ts diff --git a/packages/web/src/components/LoginForm/index.tsx b/packages/web/src/components/LoginForm/index.tsx index 64759980..b2354c31 100644 --- a/packages/web/src/components/LoginForm/index.tsx +++ b/packages/web/src/components/LoginForm/index.tsx @@ -51,9 +51,8 @@ function renderFields(props: { loading: boolean }) { Login - - - Don't have an Automatisch account yet? + + Don't have an Automatisch account yet? Sign Up diff --git a/packages/web/src/components/SignUpForm/index.ee.tsx b/packages/web/src/components/SignUpForm/index.ee.tsx index 1f95ee08..b2a85370 100644 --- a/packages/web/src/components/SignUpForm/index.ee.tsx +++ b/packages/web/src/components/SignUpForm/index.ee.tsx @@ -8,10 +8,11 @@ import * as yup from 'yup'; import useAuthentication from 'hooks/useAuthentication'; import * as URLS from 'config/urls'; -import { LOGIN } from 'graphql/mutations/login'; +import { CREATE_USER } from 'graphql/mutations/create-user.ee'; import Form from 'components/Form'; import TextField from 'components/TextField'; import { yupResolver } from '@hookform/resolvers/yup'; +import { LOGIN } from 'graphql/mutations/login'; const validationSchema = yup.object().shape({ fullName: yup.string().required(), @@ -33,6 +34,7 @@ const initialValue = { function SignUpForm() { const navigate = useNavigate(); const authentication = useAuthentication(); + const [createUser] = useMutation(CREATE_USER); const [login, { loading }] = useMutation(LOGIN); React.useEffect(() => { @@ -42,9 +44,16 @@ function SignUpForm() { }, [authentication.isAuthenticated]); const handleSubmit = async (values: any) => { + const { fullName, email, password } = values; + await createUser({ + variables: { + input: { fullName, email, password }, + }, + }); + const { data } = await login({ variables: { - input: values, + input: { email, password }, }, }); @@ -53,8 +62,6 @@ function SignUpForm() { authentication.updateToken(token); }; - //const render = React.useMemo(() => renderFields({ loading }), [loading]); - return ( Date: Fri, 3 Mar 2023 18:40:55 +0300 Subject: [PATCH 5/7] feat: remove helperText if there is no error --- .../src/components/SignUpForm/index.ee.tsx | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/web/src/components/SignUpForm/index.ee.tsx b/packages/web/src/components/SignUpForm/index.ee.tsx index b2a85370..e3ed3726 100644 --- a/packages/web/src/components/SignUpForm/index.ee.tsx +++ b/packages/web/src/components/SignUpForm/index.ee.tsx @@ -15,8 +15,8 @@ import { yupResolver } from '@hookform/resolvers/yup'; import { LOGIN } from 'graphql/mutations/login'; const validationSchema = yup.object().shape({ - fullName: yup.string().required(), - email: yup.string().email().required(), + fullName: yup.string().trim().required(), + email: yup.string().trim().email().required(), password: yup.string().required(), confirmPassword: yup .string() @@ -24,7 +24,7 @@ const validationSchema = yup.object().shape({ .oneOf([yup.ref('password')], 'Passwords must match'), }); -const initialValue = { +const initialValues = { fullName: '', email: '', password: '', @@ -79,7 +79,7 @@ function SignUpForm() { Date: Fri, 3 Mar 2023 18:43:18 +0300 Subject: [PATCH 6/7] feat: remove helperText from profile setting page if there is no error --- packages/web/src/pages/ProfileSettings/index.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/web/src/pages/ProfileSettings/index.tsx b/packages/web/src/pages/ProfileSettings/index.tsx index 0c9580c4..af3de5b4 100644 --- a/packages/web/src/pages/ProfileSettings/index.tsx +++ b/packages/web/src/pages/ProfileSettings/index.tsx @@ -153,7 +153,9 @@ function ProfileSettings() { margin="normal" type="password" error={touchedFields.password && !!errors?.password} - helperText={errors?.password?.message || ' '} + helperText={ + (touchedFields.password && errors?.password?.message) || '' + } />