Skip to content

Commit

Permalink
refactor: move sgid and email login components to their own dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
karrui committed Dec 28, 2023
1 parent 869bbe1 commit b259674
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 29 deletions.
1 change: 0 additions & 1 deletion src/features/sign-in/components/Email/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button } from '@opengovsg/design-system-react'
import { useSignInContext } from '../SignInContext'

export const EmailSignInButton = (): JSX.Element | null => {
export const EmailLoginButton = (): JSX.Element | null => {
const { proceedToEmail } = useSignInContext()

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useCallback } from 'react'
import { type VfnStepData, useSignInContext } from './SignInContext'
import { type VfnStepData, useSignInContext } from '../SignInContext'
import { EmailInput } from './Emailnput'
import { VerificationInput } from './VerificationInput'

export const SignInForm = () => {
export const EmailLoginForm = () => {
const { setVfnStepData, vfnStepData } = useSignInContext()

const handleOnSuccessEmail = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useEffect } from 'react'
import { useZodForm } from '~/lib/form'
import { trpc } from '~/utils/trpc'
import { emailSignInSchema } from '~/schemas/auth/email/sign-in'
import { type VfnStepData } from './SignInContext'
import { type VfnStepData } from '../SignInContext'

interface EmailInputProps {
onSuccess: (props: VfnStepData) => void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CALLBACK_URL_KEY } from '~/constants/params'
import { useZodForm } from '~/lib/form'
import { HOME } from '~/lib/routes'
import { trpc } from '~/utils/trpc'
import { useSignInContext } from './SignInContext'
import { useSignInContext } from '../SignInContext'
import { ResendOtpButton } from './ResendOtpButton'
import { useLoginState } from '~/features/auth'
import { emailVerifyOtpSchema } from '~/schemas/auth/email/sign-in'
Expand Down
2 changes: 2 additions & 0 deletions src/features/sign-in/components/EmailLogin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './EmailLoginButton'
export * from './EmailLoginForm'
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { useMemo } from 'react'
import { useSignInContext } from '../SignInContext'
import { EmailSignInState } from './EmailSignInState'
import { InitialSignInState } from './InitialSignInState'
import { InitialLoginStep } from './InitialLoginStep'
import { Flex } from '@chakra-ui/react'
import { EmailLoginStep } from './EmailLoginStep'

export const CurrentSignInState = (): JSX.Element => {
export const CurrentLoginStep = (): JSX.Element => {
const { state } = useSignInContext()

const stateToRender = useMemo(() => {
const stepToRender = useMemo(() => {
switch (state) {
case 'initial':
return <InitialSignInState />
return <InitialLoginStep />
case 'email':
return <EmailSignInState />
return <EmailLoginStep />
}
}, [state])

return (
// Fixed height so the page can be (relatively) centered without any layout shift.
<Flex w="100%" h={{ lg: '16rem' }}>
{stateToRender}
{stepToRender}
</Flex>
)
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Icon, Stack } from '@chakra-ui/react'
import { Button } from '@opengovsg/design-system-react'
import { BiLeftArrowAlt } from 'react-icons/bi'
import { SignInForm } from '../SignInForm'
import { EmailLoginForm } from '../EmailLogin'
import { useSignInContext } from '../SignInContext'

export const EmailSignInState = (): JSX.Element => {
export const EmailLoginStep = (): JSX.Element => {
const { backToInitial } = useSignInContext()

return (
Expand All @@ -17,7 +17,7 @@ export const EmailSignInState = (): JSX.Element => {
>
Back
</Button>
<SignInForm />
<EmailLoginForm />
</Stack>
)
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Stack, Text } from '@chakra-ui/react'

import { EmailSignInButton } from '../Email'
import { SgidLoginButton } from '../SgidLoginButton'
import { SgidLoginButton } from '../SgidLogin'
import { EmailLoginButton, EmailLoginForm } from '../EmailLogin'
import { useEnv } from '~/hooks/useEnv'
import { useFeatures } from '~/components/AppProviders'
import { SignInForm } from '../SignInForm'

export const InitialSignInState = (): JSX.Element => {
export const InitialLoginStep = (): JSX.Element => {
const {
env: { NEXT_PUBLIC_APP_NAME: title },
} = useEnv()
Expand All @@ -18,10 +17,10 @@ export const InitialSignInState = (): JSX.Element => {
{title}
</Text>
{!sgid ? (
<SignInForm />
<EmailLoginForm />
) : (
<Stack gap="1.5rem">
<EmailSignInButton />
<EmailLoginButton />
<SgidLoginButton />
</Stack>
)}
Expand Down
1 change: 1 addition & 0 deletions src/features/sign-in/components/LoginStep/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './CurrentLoginStep'
1 change: 1 addition & 0 deletions src/features/sign-in/components/SgidLogin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './SgidLoginButton'
1 change: 0 additions & 1 deletion src/features/sign-in/components/SignInState/index.ts

This file was deleted.

7 changes: 3 additions & 4 deletions src/features/sign-in/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
export * from './GridLayout'
export * from './LoginImageSvgr'
export * from './LoginStep'

export * from './Emailnput'
export * from './VerificationInput'
export * from './SignInForm'
export * from './EmailLogin'

export * from './SgidLoginButton'
export * from './SgidLogin'
export * from './SgidCallback'

export * from './SignInContext'
4 changes: 2 additions & 2 deletions src/pages/sign-in/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
NonMobileSidebarGridArea,
SignInContextProvider,
} from '~/features/sign-in/components'
import { CurrentSignInState } from '~/features/sign-in/components/SignInState'
import { CurrentLoginStep } from '~/features/sign-in/components'
import { type NextPageWithLayout } from '~/lib/types'

const SignIn: NextPageWithLayout = () => {
Expand All @@ -26,7 +26,7 @@ const SignIn: NextPageWithLayout = () => {
</NonMobileSidebarGridArea>
<LoginGridArea>
<SignInContextProvider>
<CurrentSignInState />
<CurrentLoginStep />
</SignInContextProvider>
</LoginGridArea>
<NonMobileFooterLeftGridArea />
Expand Down

0 comments on commit b259674

Please sign in to comment.