diff --git a/frontend/src/App.js b/frontend/src/App.js index 7c0edab9c9..2d9c321429 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -14,11 +14,12 @@ 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' import { UserList } from './UserList' import { DmarcReportPage } from './DmarcReportPage' @@ -29,12 +30,15 @@ export default function App() { { jwt @client tfa @client + userName @client } ` const { i18n } = useLingui() - const toast = useToast() - const client = useApolloClient() - const { data } = useQuery(GET_JWT_TOKEN) + const { data, loading } = useQuery(GET_JWT_TOKEN) + + if (loading) { + return

Loading...

+ } return ( <> @@ -68,21 +72,8 @@ 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 )} @@ -103,6 +94,10 @@ export default function App() { + + + + diff --git a/frontend/src/DomainsPage.js b/frontend/src/DomainsPage.js index e1c1961fe0..f4774fe62d 100644 --- a/frontend/src/DomainsPage.js +++ b/frontend/src/DomainsPage.js @@ -23,10 +23,10 @@ export function DomainsPage() { This is the full list of domains - {data.domains.map((domain, i) => { + {data.domains.edges.map((edge, i) => { return ( - - {domain.url} + + {edge.node.url} ) })} diff --git a/frontend/src/SignInPage.js b/frontend/src/SignInPage.js index 246bfe464e..79abaa8969 100644 --- a/frontend/src/SignInPage.js +++ b/frontend/src/SignInPage.js @@ -36,7 +36,8 @@ export function SignInPage() { cache.writeData({ data: { jwt: signIn.authToken, - tfa: signIn.user.tfaValidated, + tfa: signIn.user.tfa, + userName: signIn.user.userName, }, }) }, @@ -92,7 +93,7 @@ export function SignInPage() { {(props) => ( // Needed for testing library // eslint-disable-next-line jsx-a11y/no-redundant-roles -
+ {({ field, form }) => ( Loading...

+ } + + if (queryUserError || updatePasswordError) { + return

Error

+ } + + return ( + + { + window.alert('coming soon!!\n' + JSON.stringify(values, null, 2)) + actions.setSubmitting(false) + }} + > + {(props) => ( + + + + User Profile + + + + Display Name: + + + + + Email: + + + + + Language: + + + + + + )} + + + + + Account Details + + + Administrative Account + Account Active + + + + + + + + + + + Change Password + + + Change your password below by entering and confirming a new password. + + + { + // Submit GraphQL mutation + console.log(values) + 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 (!updatePasswordError) { + console.log(updatePasswordData) + toast({ + title: 'Password Updated.', + description: 'You have successfully changed your password.', + status: 'success', + duration: 9000, + isClosable: true, + }) + } + }} + > + {({ handleSubmit, isSubmitting }) => ( +
+ + + + + + + )} +
+
+
+ ) +} + +UserPage.propTypes = { userName: string.isRequired } diff --git a/frontend/src/__tests__/App.test.js b/frontend/src/__tests__/App.test.js index 5f0c6efada..3e67739ed3 100644 --- a/frontend/src/__tests__/App.test.js +++ b/frontend/src/__tests__/App.test.js @@ -24,7 +24,11 @@ const mocks = [ query: gql` { domains(organization: BOC) { - url + edges { + node { + url + } + } } } `, @@ -32,14 +36,20 @@ const mocks = [ }, result: { data: { - domains: [ - { - url: 'canada.ca', - }, - { - url: 'alpha.canada.ca', - }, - ], + domains: { + edges: [ + { + node: { + url: 'canada.ca', + }, + }, + { + node: { + url: 'alpha.canada.ca', + }, + }, + ], + }, }, }, }, diff --git a/frontend/src/__tests__/SignInPage.test.js b/frontend/src/__tests__/SignInPage.test.js index ce39565afe..7b80ffef19 100644 --- a/frontend/src/__tests__/SignInPage.test.js +++ b/frontend/src/__tests__/SignInPage.test.js @@ -120,7 +120,7 @@ describe('', () => { signIn(userName: $userName, password: $password) { user { userName - tfaValidated + tfa } authToken } @@ -136,8 +136,7 @@ describe('', () => { signIn: { user: { userName: 'Thalia.Rosenbaum@gmail.com', - failedLoginAttempts: 4, - tfaValidated: false, + tfa: false, }, authToken: 'test123stringJWT', }, @@ -153,7 +152,7 @@ describe('', () => { initialIndex: 0, }) - const { container, getByRole } = render( + const { container, getByRole, queryByText } = render( @@ -168,6 +167,11 @@ describe('', () => { , ) + await waitFor(() => { + expect( + queryByText(/Sign in with your username and password./i), + ).toBeInTheDocument() + }) const email = container.querySelector('#email') const password = container.querySelector('#password') diff --git a/frontend/src/graphql/mutations.js b/frontend/src/graphql/mutations.js index a244f4cd09..698dcd8ce5 100644 --- a/frontend/src/graphql/mutations.js +++ b/frontend/src/graphql/mutations.js @@ -25,7 +25,7 @@ export const SIGN_IN = gql` signIn(userName: $userName, password: $password) { user { userName - tfaValidated + tfa } authToken } @@ -41,3 +41,5 @@ export const VALIDATE_TWO_FACTOR = gql` } } ` + +export default '' diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js index 845af9555a..2bb464a2e6 100644 --- a/frontend/src/graphql/queries.js +++ b/frontend/src/graphql/queries.js @@ -3,7 +3,11 @@ import gql from 'graphql-tag' export const DOMAINS = gql` { domains(organization: BOC) { - url + edges { + node { + url + } + } } } `