Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
fix: add changes for mobile register
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh committed Aug 4, 2023
1 parent 3c2aa92 commit dc30203
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 1,117 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dependencies": {
"@emotion/react": "11.11.1",
"@emotion/styled": "11.11.0",
"@graasp/query-client": "1.2.0",
"@graasp/query-client": "1.3.2",
"@graasp/sdk": "1.2.0",
"@graasp/translations": "1.15.1",
"@graasp/ui": "3.2.7",
Expand Down
11 changes: 9 additions & 2 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import * as Sentry from '@sentry/react';
import { Route, BrowserRouter as Router, Routes } from 'react-router-dom';

import { HOME_PATH, SIGN_UP_PATH, buildSignInPath } from '../config/paths';
import {
HOME_PATH,
MOBILE_AUTH_PATH,
SIGN_IN_PATH,
SIGN_UP_PATH,
} from '../config/paths';
import ErrorFallback from './ErrorFallback';
import MobileAuth from './MobileAuth';
import Redirection from './Redirection';
import SignIn from './SignIn';
import SignUp from './SignUp';
Expand All @@ -12,9 +18,10 @@ const App = () => (
<Router>
<Redirection>
<Routes>
<Route path={buildSignInPath()} element={<SignIn />} />
<Route path={SIGN_IN_PATH} element={<SignIn />} />
<Route path={SIGN_UP_PATH} element={<SignUp />} />
<Route path={HOME_PATH} element={<SignIn />} />
<Route path={MOBILE_AUTH_PATH} element={<MobileAuth />} />
</Routes>
</Redirection>
</Router>
Expand Down
56 changes: 56 additions & 0 deletions src/components/MobileAuth.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Link } from 'react-router-dom';

import { Android, Apple, DeviceUnknown } from '@mui/icons-material';
import { Button, Stack, Typography } from '@mui/material';

import { HOME_PATH } from '../config/paths';
import FullscreenContainer from './FullscreenContainer';

const MobileAuth = (): JSX.Element => {
return (
<FullscreenContainer>
<Stack
justifyContent="center"
alignItems="center"
direction="column"
spacing={2}
>
<DeviceUnknown fontSize="large" color="primary" />
<Typography>
It looks like you requested a mobile link but you do not have our app
installed on this device.
</Typography>
<Button component={Link} to={''} variant="contained">
<Stack
direction="column"
alignItems="center"
justifyContent="center"
px={1}
py={{ xs: 1, sm: 2 }}
textTransform="none"
>
<Apple />
<Typography>Get from the Apple App Store</Typography>
</Stack>
</Button>
<Button component={Link} to={''} variant="contained">
<Stack
direction="column"
alignItems="center"
justifyContent="center"
px={1}
py={{ xs: 1, sm: 2 }}
textTransform="none"
>
<Android />
<Typography>Get from the Google Play Store</Typography>
</Stack>
</Button>
<Typography component={Link} to={HOME_PATH} variant="caption">
Go back Home
</Typography>
</Stack>
</FullscreenContainer>
);
};
export default MobileAuth;
5 changes: 3 additions & 2 deletions src/components/SignIn.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC, useState } from 'react';
import { Link } from 'react-router-dom';
import { Link, useLocation } from 'react-router-dom';

import { RecaptchaAction } from '@graasp/sdk';
import { AUTH } from '@graasp/translations';
Expand Down Expand Up @@ -45,6 +45,7 @@ const SignIn: FC = () => {
const { executeCaptcha } = useRecaptcha();

const { isMobile, challenge } = useMobileLogin();
const { search } = useLocation();

const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
Expand Down Expand Up @@ -210,7 +211,7 @@ const SignIn: FC = () => {
)}
</Stack>
</FormControl>
<Link to={SIGN_UP_PATH}>{t(SIGN_UP_LINK_TEXT)}</Link>
<Link to={`${SIGN_UP_PATH}${search}`}>{t(SIGN_UP_LINK_TEXT)}</Link>
</>
);

Expand Down
35 changes: 25 additions & 10 deletions src/components/SignUp.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChangeEventHandler, useEffect, useState } from 'react';
import { Link, useSearchParams } from 'react-router-dom';
import { Link, useLocation, useSearchParams } from 'react-router-dom';

import { RecaptchaAction } from '@graasp/sdk';
import { AUTH } from '@graasp/translations';
Expand All @@ -9,8 +9,8 @@ import { Stack } from '@mui/material';
import FormControl from '@mui/material/FormControl';
import Typography from '@mui/material/Typography';

import { SIGN_IN_PATH } from '../config/constants';
import { useAuthTranslation } from '../config/i18n';
import { buildSignInPath } from '../config/paths';
import { hooks, mutations } from '../config/queryClient';
import {
EMAIL_SIGN_UP_FIELD_ID,
Expand All @@ -19,6 +19,7 @@ import {
SIGN_UP_HEADER_ID,
} from '../config/selectors';
import { useRecaptcha } from '../context/RecaptchaContext';
import { useMobileLogin } from '../hooks/mobile';
import { emailValidator, nameValidator } from '../utils/validation';
import EmailInput from './EmailInput';
import FullscreenContainer from './FullscreenContainer';
Expand All @@ -32,6 +33,8 @@ const SignUp = () => {
const { t } = useAuthTranslation();
const { executeCaptcha } = useRecaptcha();

const { isMobile, challenge } = useMobileLogin();

const [email, setEmail] = useState<string>('');
const [name, setName] = useState<string>('');
const [nameError, setNameError] = useState<string | null>(null);
Expand All @@ -41,7 +44,10 @@ const SignUp = () => {

const { mutateAsync: signUp, isSuccess: signUpSuccess } =
mutations.useSignUp();
const { mutateAsync: mobileSignUp, isSuccess: mobileSignUpSuccess } =
mutations.useMobileSignUp();
const [searchParams] = useSearchParams();
const { search } = useLocation();

const {
data: invitation,
Expand Down Expand Up @@ -78,12 +84,21 @@ const SignUp = () => {
setNameError(checkingUsername);
setShouldValidate(true);
} else {
const token = await executeCaptcha(RecaptchaAction.SignUp);
await signUp({
name: name.trim(),
email: lowercaseEmail,
captcha: token,
});
const token = await executeCaptcha(
isMobile ? RecaptchaAction.SignUpMobile : RecaptchaAction.SignUp,
);
await (isMobile
? mobileSignUp({
name: name.trim(),
email: lowercaseEmail,
captcha: token,
challenge,
})
: signUp({
name: name.trim(),
email: lowercaseEmail,
captcha: token,
}));
setSuccessView(true);
}
};
Expand Down Expand Up @@ -119,13 +134,13 @@ const SignUp = () => {
</Button>
</Stack>
</FormControl>
<Link to={buildSignInPath()}>{t(SIGN_IN_LINK_TEXT)}</Link>
<Link to={`${SIGN_IN_PATH}${search}`}>{t(SIGN_IN_LINK_TEXT)}</Link>
</>
);

return (
<FullscreenContainer>
{signUpSuccess && successView ? (
{(signUpSuccess || mobileSignUpSuccess) && successView ? (
<SuccessContent
title={t(AUTH.SIGN_UP_SUCCESS_TITLE)}
email={email}
Expand Down
7 changes: 2 additions & 5 deletions src/config/paths.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import qs from 'qs';

export const buildSignInPath = (to?: string) =>
`/signin${qs.stringify({ to }, { addQueryPrefix: true })}`;
export const SIGN_IN_PATH = '/signin';
export const SIGN_UP_PATH = '/signup';
export const HOME_PATH = '/';
export const SIGN_IN_PATH = '/signin';
export const MOBILE_AUTH_PATH = '/auth';
Loading

0 comments on commit dc30203

Please sign in to comment.