-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b8a4c3
commit a59a7f2
Showing
5 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from "react"; | ||
import { transport } from "../../../environment"; | ||
import { UserClient } from '@protos/user.client'; | ||
import { ActivateUserRequest } from '@protos/user'; | ||
|
||
const useActivateUserRPC = () => { | ||
const client = React.useMemo(() => new UserClient(transport), []); | ||
|
||
const activateUser = React.useCallback( async (token: string, password: string) => { | ||
const request: ActivateUserRequest = ActivateUserRequest.create(); | ||
request.token = token; | ||
request.password = password; | ||
const response = await client.activateUser(request, {}).response; | ||
return response.token; | ||
}, []); | ||
|
||
return { | ||
activateUser, | ||
}; | ||
|
||
}; | ||
|
||
export default useActivateUserRPC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { useState } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { Box, Paper, Typography, TextField, Button } from '@mui/material'; | ||
import useActivateUserRPC from '@hooks/backend/userService/useActivateUserRPC'; | ||
import AuthContext from '@contexts/AuthContext'; | ||
import { toast } from 'react-toastify'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
const InvitationSignup: React.FC = () => { | ||
const [password, setPassword] = useState<string>(''); | ||
const [submitted, setSubmitted] = useState<boolean>(false); | ||
const [error, setError] = useState<string | null>(null); | ||
|
||
const { loginWithToken } = React.useContext(AuthContext); | ||
const { activateUser } = useActivateUserRPC(); | ||
const { activationToken } = useParams<{ activationToken: string }>(); | ||
|
||
const { t } = useTranslation(); | ||
|
||
const signIn = async () => { | ||
try { | ||
setError(null); // Clear any previous errors before attempting the operation again | ||
const loginToken = await activateUser(activationToken, password); | ||
loginWithToken(loginToken); | ||
toast.success(t("loginPage.loginSuccess")); | ||
setSubmitted(true); | ||
} catch (err) { | ||
setError("Invitation déjà utilisée!"); // Set the error state | ||
} | ||
}; | ||
|
||
return ( | ||
<Box sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: 'calc(100vh - 110px)' }}> | ||
<Paper sx={{ p: 2, width: '25em' }}> | ||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}> | ||
<Typography variant="h6">Choisissez votre nouveau mot de passe</Typography> | ||
{submitted && (<Typography>Votre compte a été correctement créé</Typography>)} | ||
{!submitted && ( | ||
<> | ||
<TextField | ||
type="password" | ||
name='password' | ||
label="Mot de passe" | ||
value={password} | ||
required | ||
onChange={(e) => setPassword(e.target.value)} | ||
/> | ||
{error && ( | ||
<Typography color="error" variant="body2">{error}</Typography> // Display error inline | ||
)} | ||
<Button type="submit" variant="contained" color="primary" onClick={signIn} > | ||
Créer un compte | ||
</Button> | ||
</> | ||
)} | ||
</Box> | ||
</Paper> | ||
</Box> | ||
); | ||
} | ||
|
||
export default InvitationSignup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters