Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react): sign in feature #2683

Merged
merged 59 commits into from Sep 14, 2021
Merged

Conversation

karrui
Copy link
Contributor

@karrui karrui commented Aug 26, 2021

Problem

This PR implements the sign in feature, with mocked API calls using msw. This allows for the storybook to be rendered and working almost as close to the real thing (calling server endpoints) as possible.

Closes #2489

Solution

Features:

  • Add LoginPage component and related stories. Subcomponent consists of

    • OtpForm,
    • LoginForm,
    • ResendOtpButton. This component implements a cooldown timer of 60 seconds using the a newly implemented useInterval hook.
  • Add a bunch of new hooks to facilitate this feature:

    • useLocalStorage used for storing logged in state (in favour of storying the user object, since the user object will be stale and can be fetched from the /user endpoint)
    • useInterval used for rendering updates in an interval
    • useUser basically a react-query hook to retrieve the current logged in user
    • AuthContext/useAuth hook providing a bunch of authentication related functions
  • Add a bunch of services (copy-pasted from AngularJS folder) to facilitate this feature

    • UserService
    • AuthService
    • new ApiService (using axios, but may switch to wretched?)
  • Add msw package for mocking API calls. Used inside storybook (and locally, can be disabled when the server is up)

Before & After Screenshots

Working flow in storybook

No need to scroll on smaller laptop screen resolutions

1366px x 768px desktop layout
localhost_6006_iframe html_id=pages-loginpage--desktop args= viewMode=story(13_ Laptop 1366px)

1280px x 800px desktop layout
localhost_6006_iframe html_id=pages-loginpage--desktop args= viewMode=story(13_ Laptop 1280px)

Deploy Notes

New dependencies:

  • react-query for making api calls

New dev dependencies:

  • msw for mocking network calls in app
  • msw-storybook-addon for mocking network calls in storybook

partially moved from angularjs service
lacking footer, will probably do footer first then
# Conflicts:
#	frontend/__tests__/storyshots/jest.config.js
#	frontend/tsconfig.paths.json
@karrui karrui mentioned this pull request Aug 26, 2021
# Conflicts:
#	frontend/package-lock.json
#	frontend/package.json
* Mock Service Worker (0.35.0).
* @see https://github.com/mswjs/msw
* - Please do NOT modify this file.
* - Please do NOT serve this file on production.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I ran npm run build and saw that mockServiceWorker.js is included in frontend/build (which presumably will change to dist/frontend once we configure it correctly). if we use app.use(express.static(path.resolve('dist/frontend'))) (as per #2675) will that mean someone would be able to get this file from form.gov.sg/mockServiceWorker.js?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes they would, but it would be useless because the service worker would not be registered anyways. I guess we can add a .dockerignore entry and it'll not be in the image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good

frontend/src/hooks/useUser.ts Outdated Show resolved Hide resolved
frontend/src/contexts/AuthContext.tsx Outdated Show resolved Hide resolved
frontend/src/index.tsx Outdated Show resolved Hide resolved
frontend/src/mocks/msw/handlers/auth.ts Show resolved Hide resolved
frontend/src/pages/login/LoginPage.tsx Outdated Show resolved Hide resolved
frontend/src/pages/login/LoginPage.tsx Outdated Show resolved Hide resolved
frontend/src/services/ApiService.ts Show resolved Hide resolved
)

// Grid area styling for the left sidebar that only displays on tablet and desktop breakpoints.
const NonMobileSidebarGridArea: FC = ({ children }) => (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSX.Element? haha

@karrui karrui merged commit 20a6d2b into form-v2/develop Sep 14, 2021
@karrui karrui deleted the form-v2/sign-in-flow-basic branch September 14, 2021 09:41
@justynoh justynoh mentioned this pull request Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants