From 74be8d7ad2cb9c5a708a4d2e3581b43f1094540a Mon Sep 17 00:00:00 2001 From: Matt Peachey Date: Wed, 25 Mar 2020 11:28:00 -0300 Subject: [PATCH 01/16] Add UserPage Component. Begin populating component --- frontend/src/App.js | 8 +++++ frontend/src/UserPage.js | 73 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 frontend/src/UserPage.js diff --git a/frontend/src/App.js b/frontend/src/App.js index 5cef5328b7..c0a7e8e91a 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -19,6 +19,7 @@ import { SkipLink } from './SkipLink' import { useQuery, useApolloClient } from '@apollo/react-hooks' import gql from 'graphql-tag' import { TwoFactorNotificationBar } from './TwoFactorNotificationBar' +import { UserPage } from './UserPage' export default function App() { // Hooks to be used with this functional component @@ -82,6 +83,9 @@ export default function App() { Sign Out )} + + User Profile + {// Dynamically show the TwoFactorNotification bar data && !data.tfa && } @@ -94,6 +98,10 @@ export default function App() { + + + + diff --git a/frontend/src/UserPage.js b/frontend/src/UserPage.js new file mode 100644 index 0000000000..a4cb8a4f45 --- /dev/null +++ b/frontend/src/UserPage.js @@ -0,0 +1,73 @@ +import React from 'react' + +import { useFormik } from 'formik' + +import { Stack, SimpleGrid, Button, Text, Select, Input } from '@chakra-ui/core' + +export function UserPage() { + const formik = useFormik({ + initialValues: { + email: 'steve@email.gc.ca', + lang: 'select option', + displayName: 'steve', + }, + onSubmit: values => { + window.alert(JSON.stringify(values, null, 2)) + }, + }) + return ( + +
+ + + User Profile + + + + Display Name: + + + + + Email: + + + + + Language: + + + + +
+ + + +
+ ) +} From 69121e55b6770b96d2ec44eea449c0d41aeb0701 Mon Sep 17 00:00:00 2001 From: Matt Peachey Date: Wed, 25 Mar 2020 13:21:39 -0300 Subject: [PATCH 02/16] Use a unique formik hook for user details form --- frontend/src/UserPage.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/frontend/src/UserPage.js b/frontend/src/UserPage.js index a4cb8a4f45..51ab8f7be6 100644 --- a/frontend/src/UserPage.js +++ b/frontend/src/UserPage.js @@ -5,7 +5,7 @@ import { useFormik } from 'formik' import { Stack, SimpleGrid, Button, Text, Select, Input } from '@chakra-ui/core' export function UserPage() { - const formik = useFormik({ + const userDetailsFormik = useFormik({ initialValues: { email: 'steve@email.gc.ca', lang: 'select option', @@ -17,7 +17,7 @@ export function UserPage() { }) return ( -
+ User Profile @@ -30,8 +30,8 @@ export function UserPage() { id="displayName" name="displayName" type="text" - onChange={formik.handleChange} - value={formik.values.displayName} + onChange={userDetailsFormik.handleChange} + value={userDetailsFormik.values.displayName} /> @@ -42,8 +42,8 @@ export function UserPage() { id="email" name="email" type="email" - onChange={formik.handleChange} - value={formik.values.email} + onChange={userDetailsFormik.handleChange} + value={userDetailsFormik.values.email} /> @@ -55,8 +55,8 @@ export function UserPage() { name="lang" type="text" placeholder="Select option" - onChange={formik.handleChange} - value={formik.values.lang} + onChange={userDetailsFormik.handleChange} + value={userDetailsFormik.values.lang} > @@ -66,7 +66,10 @@ export function UserPage() {
- + + Account Details + +
) From 7ded3fd700b2e9ee359ad9e275991af86429bbb3 Mon Sep 17 00:00:00 2001 From: Matt Peachey Date: Wed, 25 Mar 2020 14:08:41 -0300 Subject: [PATCH 03/16] User Profile avaliable when you sign in. Add 'Account Detail' section info. Add Sign-out button and apolloClient. Add toast for signout. Remove signout button from APP.js nav bar. Add enable TFA button and link to correct page. Improve draft layout. --- frontend/src/App.js | 26 ++------- frontend/src/UserPage.js | 118 +++++++++++++++++++++++++++++++++++---- 2 files changed, 110 insertions(+), 34 deletions(-) diff --git a/frontend/src/App.js b/frontend/src/App.js index c0a7e8e91a..b0ca2d1aad 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -14,9 +14,9 @@ import { TopBanner } from './TopBanner' import { PhaseBanner } from './PhaseBanner' import { Footer } from './Footer' import { Navigation } from './Navigation' -import { Flex, Link, CSSReset, useToast } from '@chakra-ui/core' +import { Flex, Link, CSSReset } from '@chakra-ui/core' import { SkipLink } from './SkipLink' -import { useQuery, useApolloClient } from '@apollo/react-hooks' +import { useQuery } from '@apollo/react-hooks' import gql from 'graphql-tag' import { TwoFactorNotificationBar } from './TwoFactorNotificationBar' import { UserPage } from './UserPage' @@ -30,8 +30,6 @@ export default function App() { } ` const { i18n } = useLingui() - const toast = useToast() - const client = useApolloClient() const { data } = useQuery(GET_JWT_TOKEN) return ( @@ -66,26 +64,10 @@ export default function App() { Sign In ) : ( - { - // This clears the JWT, essentially logging the user out in one go - client.writeData({ data: { jwt: null } }) // How is this done? - toast({ - title: 'Sign Out.', - description: 'You have successfully been signed out.', - status: 'success', - duration: 9000, - isClosable: true, - }) - }} - > - Sign Out + + User Profile )} - - User Profile - {// Dynamically show the TwoFactorNotification bar data && !data.tfa && } diff --git a/frontend/src/UserPage.js b/frontend/src/UserPage.js index 51ab8f7be6..281498a997 100644 --- a/frontend/src/UserPage.js +++ b/frontend/src/UserPage.js @@ -1,10 +1,32 @@ import React from 'react' import { useFormik } from 'formik' +import { useHistory } from 'react-router-dom' -import { Stack, SimpleGrid, Button, Text, Select, Input } from '@chakra-ui/core' +import { + Stack, + SimpleGrid, + Button, + Text, + Select, + Input, + NumberInput, + NumberInputField, + NumberInputStepper, + NumberIncrementStepper, + NumberDecrementStepper, + Divider, + Checkbox, + CheckboxGroup, + useToast, +} from '@chakra-ui/core' +import { useApolloClient } from '@apollo/react-hooks' export function UserPage() { + const client = useApolloClient() + const toast = useToast() + const history = useHistory() + const userDetailsFormik = useFormik({ initialValues: { email: 'steve@email.gc.ca', @@ -16,17 +38,16 @@ export function UserPage() { }, }) return ( - +
- + User Profile - + Display Name: Email: Language: - + - - Account Details - + + + Account Details + + + Administrative Account + Account Active + + + API Quota: + + + + + + + + + + Submission Quota: + + + + + + + + + + + + + + + + + + Change Password + +

PasswordConfirm componenet goes here.

-
) } From 09a58c7a7d83a22f49bada54cdc1f9f5cd57ac7f Mon Sep 17 00:00:00 2001 From: Matt Peachey Date: Wed, 25 Mar 2020 11:28:00 -0300 Subject: [PATCH 04/16] Add UserPage Component. Begin populating component --- frontend/src/App.js | 8 +++++ frontend/src/UserPage.js | 73 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 frontend/src/UserPage.js diff --git a/frontend/src/App.js b/frontend/src/App.js index 5cef5328b7..c0a7e8e91a 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -19,6 +19,7 @@ import { SkipLink } from './SkipLink' import { useQuery, useApolloClient } from '@apollo/react-hooks' import gql from 'graphql-tag' import { TwoFactorNotificationBar } from './TwoFactorNotificationBar' +import { UserPage } from './UserPage' export default function App() { // Hooks to be used with this functional component @@ -82,6 +83,9 @@ export default function App() { Sign Out )} + + User Profile + {// Dynamically show the TwoFactorNotification bar data && !data.tfa && } @@ -94,6 +98,10 @@ export default function App() { + + + + diff --git a/frontend/src/UserPage.js b/frontend/src/UserPage.js new file mode 100644 index 0000000000..a4cb8a4f45 --- /dev/null +++ b/frontend/src/UserPage.js @@ -0,0 +1,73 @@ +import React from 'react' + +import { useFormik } from 'formik' + +import { Stack, SimpleGrid, Button, Text, Select, Input } from '@chakra-ui/core' + +export function UserPage() { + const formik = useFormik({ + initialValues: { + email: 'steve@email.gc.ca', + lang: 'select option', + displayName: 'steve', + }, + onSubmit: values => { + window.alert(JSON.stringify(values, null, 2)) + }, + }) + return ( + +
+ + + User Profile + + + + Display Name: + + + + + Email: + + + + + Language: + + + + +
+ + + +
+ ) +} From 0d97178d1b4ccedf9129847a7eadda2f02f70180 Mon Sep 17 00:00:00 2001 From: Matt Peachey Date: Wed, 25 Mar 2020 13:21:39 -0300 Subject: [PATCH 05/16] Use a unique formik hook for user details form --- frontend/src/UserPage.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/frontend/src/UserPage.js b/frontend/src/UserPage.js index a4cb8a4f45..51ab8f7be6 100644 --- a/frontend/src/UserPage.js +++ b/frontend/src/UserPage.js @@ -5,7 +5,7 @@ import { useFormik } from 'formik' import { Stack, SimpleGrid, Button, Text, Select, Input } from '@chakra-ui/core' export function UserPage() { - const formik = useFormik({ + const userDetailsFormik = useFormik({ initialValues: { email: 'steve@email.gc.ca', lang: 'select option', @@ -17,7 +17,7 @@ export function UserPage() { }) return ( -
+ User Profile @@ -30,8 +30,8 @@ export function UserPage() { id="displayName" name="displayName" type="text" - onChange={formik.handleChange} - value={formik.values.displayName} + onChange={userDetailsFormik.handleChange} + value={userDetailsFormik.values.displayName} /> @@ -42,8 +42,8 @@ export function UserPage() { id="email" name="email" type="email" - onChange={formik.handleChange} - value={formik.values.email} + onChange={userDetailsFormik.handleChange} + value={userDetailsFormik.values.email} /> @@ -55,8 +55,8 @@ export function UserPage() { name="lang" type="text" placeholder="Select option" - onChange={formik.handleChange} - value={formik.values.lang} + onChange={userDetailsFormik.handleChange} + value={userDetailsFormik.values.lang} > @@ -66,7 +66,10 @@ export function UserPage() {
- + + Account Details + +
) From 12592bca116e9a1c9b1bba90195b76e83dc50d73 Mon Sep 17 00:00:00 2001 From: Matt Peachey Date: Wed, 25 Mar 2020 14:08:41 -0300 Subject: [PATCH 06/16] User Profile avaliable when you sign in. Add 'Account Detail' section info. Add Sign-out button and apolloClient. Add toast for signout. Remove signout button from APP.js nav bar. Add enable TFA button and link to correct page. Improve draft layout. --- frontend/src/App.js | 26 ++------- frontend/src/UserPage.js | 118 +++++++++++++++++++++++++++++++++++---- 2 files changed, 110 insertions(+), 34 deletions(-) diff --git a/frontend/src/App.js b/frontend/src/App.js index c0a7e8e91a..b0ca2d1aad 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -14,9 +14,9 @@ import { TopBanner } from './TopBanner' import { PhaseBanner } from './PhaseBanner' import { Footer } from './Footer' import { Navigation } from './Navigation' -import { Flex, Link, CSSReset, useToast } from '@chakra-ui/core' +import { Flex, Link, CSSReset } from '@chakra-ui/core' import { SkipLink } from './SkipLink' -import { useQuery, useApolloClient } from '@apollo/react-hooks' +import { useQuery } from '@apollo/react-hooks' import gql from 'graphql-tag' import { TwoFactorNotificationBar } from './TwoFactorNotificationBar' import { UserPage } from './UserPage' @@ -30,8 +30,6 @@ export default function App() { } ` const { i18n } = useLingui() - const toast = useToast() - const client = useApolloClient() const { data } = useQuery(GET_JWT_TOKEN) return ( @@ -66,26 +64,10 @@ export default function App() { Sign In ) : ( - { - // This clears the JWT, essentially logging the user out in one go - client.writeData({ data: { jwt: null } }) // How is this done? - toast({ - title: 'Sign Out.', - description: 'You have successfully been signed out.', - status: 'success', - duration: 9000, - isClosable: true, - }) - }} - > - Sign Out + + User Profile )} - - User Profile - {// Dynamically show the TwoFactorNotification bar data && !data.tfa && } diff --git a/frontend/src/UserPage.js b/frontend/src/UserPage.js index 51ab8f7be6..281498a997 100644 --- a/frontend/src/UserPage.js +++ b/frontend/src/UserPage.js @@ -1,10 +1,32 @@ import React from 'react' import { useFormik } from 'formik' +import { useHistory } from 'react-router-dom' -import { Stack, SimpleGrid, Button, Text, Select, Input } from '@chakra-ui/core' +import { + Stack, + SimpleGrid, + Button, + Text, + Select, + Input, + NumberInput, + NumberInputField, + NumberInputStepper, + NumberIncrementStepper, + NumberDecrementStepper, + Divider, + Checkbox, + CheckboxGroup, + useToast, +} from '@chakra-ui/core' +import { useApolloClient } from '@apollo/react-hooks' export function UserPage() { + const client = useApolloClient() + const toast = useToast() + const history = useHistory() + const userDetailsFormik = useFormik({ initialValues: { email: 'steve@email.gc.ca', @@ -16,17 +38,16 @@ export function UserPage() { }, }) return ( - +
- + User Profile - + Display Name: Email: Language: - + - - Account Details - + + + Account Details + + + Administrative Account + Account Active + + + API Quota: + + + + + + + + + + Submission Quota: + + + + + + + + + + + + + + + + + + Change Password + +

PasswordConfirm componenet goes here.

-
) } From 3a850d1456ba7d1a9a4d78f7ec803de847f519bd Mon Sep 17 00:00:00 2001 From: Matt Peachey Date: Tue, 31 Mar 2020 14:59:12 -0300 Subject: [PATCH 07/16] Add passwordConfirmation field to userPage. TODO: fix schema.faker.graphql. --- frontend/src/App.js | 3 +++ frontend/src/UserPage.js | 48 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/frontend/src/App.js b/frontend/src/App.js index b0ca2d1aad..1dcb0e6f77 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -68,6 +68,9 @@ export default function App() { User Profile )} + + UserPage + {// Dynamically show the TwoFactorNotification bar data && !data.tfa && } diff --git a/frontend/src/UserPage.js b/frontend/src/UserPage.js index 281498a997..03c271f488 100644 --- a/frontend/src/UserPage.js +++ b/frontend/src/UserPage.js @@ -1,6 +1,6 @@ import React from 'react' -import { useFormik } from 'formik' +import { useFormik, Formik } from 'formik' import { useHistory } from 'react-router-dom' import { @@ -21,6 +21,7 @@ import { useToast, } from '@chakra-ui/core' import { useApolloClient } from '@apollo/react-hooks' +import { PasswordConfirmation } from './PasswordConfirmation' export function UserPage() { const client = useApolloClient() @@ -133,10 +134,22 @@ export function UserPage() { - - @@ -163,7 +176,34 @@ export function UserPage() { Change Password -

PasswordConfirm componenet goes here.

+ + Change your password below by entering and confirming a new password. + + + { + console.log(values) + window.alert("Change password submitted. TODO: Implement GQL call") + }} + > + {({ handleSubmit, isSubmitting }) => ( +
+ + + + + + + )} +
) From 1508db05ccf04fedee28d8123293c49621041ad3 Mon Sep 17 00:00:00 2001 From: Matt Peachey Date: Wed, 1 Apr 2020 08:06:16 -0300 Subject: [PATCH 08/16] Add gql mutation for updating password on UserPage. Add export default of empty string to frontend/src/graphql/mutations. --- frontend/src/CreateUserPage.js | 2 +- frontend/src/UserPage.js | 55 +++++++++++++++++++++++++++++-- frontend/src/graphql/mutations.js | 2 ++ 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/frontend/src/CreateUserPage.js b/frontend/src/CreateUserPage.js index 6e10515f92..8f888e7067 100644 --- a/frontend/src/CreateUserPage.js +++ b/frontend/src/CreateUserPage.js @@ -57,7 +57,7 @@ export function CreateUserPage() { { + onSubmit={async values => { createUser({ variables: { userName: values.email, diff --git a/frontend/src/UserPage.js b/frontend/src/UserPage.js index 03c271f488..8db33be71b 100644 --- a/frontend/src/UserPage.js +++ b/frontend/src/UserPage.js @@ -20,14 +20,46 @@ import { CheckboxGroup, useToast, } from '@chakra-ui/core' -import { useApolloClient } from '@apollo/react-hooks' +import { useApolloClient, useMutation } from '@apollo/react-hooks' import { PasswordConfirmation } from './PasswordConfirmation' +import gql from 'graphql-tag' export function UserPage() { + // TODO: Move to mutations folder + const UPDATE_PASSWORD = gql` + mutation UpdatePassword( + $userName: EmailAddress! + $password: String! + $confirmPassword: String! + ) { + updatePassword( + userName: $userName + password: $password + confirmPassword: $confirmPassword + ) { + user { + userName + } + } + } + ` + const client = useApolloClient() const toast = useToast() const history = useHistory() + const [updatePassword, { loading, error, data }] = useMutation( + UPDATE_PASSWORD, + ) + + if (data) { + console.log(data) + } + + if (loading) { + console.log('loading') + } + const userDetailsFormik = useFormik({ initialValues: { email: 'steve@email.gc.ca', @@ -181,10 +213,27 @@ export function UserPage() { { + // Submit GraphQL mutation console.log(values) - window.alert("Change password submitted. TODO: Implement GQL call") + await updatePassword({ + variables: { + userName: 'testuser@test.ca', // This needs to be retreived from a seperate GQL query or props that will populate this entire page with data. + password: values.password, + confirmPassword: values.confirmPassword, + }, + }) + + if (!error) { + toast({ + title: 'Password Updated.', + description: 'You have successfully changed your password.', + status: 'success', + duration: 9000, + isClosable: true, + }) + } }} > {({ handleSubmit, isSubmitting }) => ( diff --git a/frontend/src/graphql/mutations.js b/frontend/src/graphql/mutations.js index a244f4cd09..d3e84783c7 100644 --- a/frontend/src/graphql/mutations.js +++ b/frontend/src/graphql/mutations.js @@ -41,3 +41,5 @@ export const VALIDATE_TWO_FACTOR = gql` } } ` + +export default '' From 47038541af607d93b7f5aa2c6850f0c4ac7e99a2 Mon Sep 17 00:00:00 2001 From: Matt Peachey Date: Wed, 1 Apr 2020 14:06:13 -0300 Subject: [PATCH 09/16] Change useFormik() hook to component in userPage --- frontend/src/UserPage.js | 197 +++++++++++++++++++-------------------- 1 file changed, 96 insertions(+), 101 deletions(-) diff --git a/frontend/src/UserPage.js b/frontend/src/UserPage.js index 8db33be71b..8926a3ceb2 100644 --- a/frontend/src/UserPage.js +++ b/frontend/src/UserPage.js @@ -1,6 +1,7 @@ +/* eslint react/prop-types: 0 */ import React from 'react' -import { useFormik, Formik } from 'formik' +import { Formik } from 'formik' import { useHistory } from 'react-router-dom' import { @@ -10,17 +11,12 @@ import { Text, Select, Input, - NumberInput, - NumberInputField, - NumberInputStepper, - NumberIncrementStepper, - NumberDecrementStepper, Divider, Checkbox, CheckboxGroup, useToast, } from '@chakra-ui/core' -import { useApolloClient, useMutation } from '@apollo/react-hooks' +import { useApolloClient, useMutation, useQuery } from '@apollo/react-hooks' import { PasswordConfirmation } from './PasswordConfirmation' import gql from 'graphql-tag' @@ -44,81 +40,112 @@ export function UserPage() { } ` + const QUERY_USER = gql` + query User($userName: EmailAddress!) { + user(userName: $username) { + userName + displayName + lang + } + } + ` + const client = useApolloClient() const toast = useToast() const history = useHistory() - const [updatePassword, { loading, error, data }] = useMutation( - UPDATE_PASSWORD, - ) + const [ + updatePassword, + { + loading: updatePasswordLoading, + error: updatePasswordError, + data: updatePasswordData, + }, + ] = useMutation(UPDATE_PASSWORD) - if (data) { - console.log(data) + const { + loading: queryUserLoading, + error: queryUserError, + data: queryUserData, + } = useQuery(QUERY_USER) + + if (updatePasswordData || queryUserData) { + console.log(updatePasswordData) } - if (loading) { + if (updatePasswordLoading || queryUserLoading) { console.log('loading') } - const userDetailsFormik = useFormik({ - initialValues: { - email: 'steve@email.gc.ca', - lang: 'select option', - displayName: 'steve', - }, - onSubmit: values => { - window.alert(JSON.stringify(values, null, 2)) - }, - }) + if(queryUserError){ + console.log(queryUserError) + } + return ( -
- - - User Profile - + { + setTimeout(() => { + window.alert(JSON.stringify(values, null, 2)) + actions.setSubmitting(false) + }, 1000) + }} + > + {(props) => ( + + + + User Profile + - - Display Name: - - + + Display Name: + + - - Email: - - + + Email: + + - - Language: - - - - - + + Language: + + + +
+ + )} +
@@ -132,38 +159,6 @@ export function UserPage() { Administrative Account Account Active - - API Quota: - - - - - - - - - - Submission Quota: - - - - - - - -