-
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
5509150
commit 88cb3bf
Showing
6 changed files
with
187 additions
and
6 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { | ||
generatePath, | ||
useNavigate, | ||
useParams, | ||
} from 'react-router-dom'; | ||
|
||
import routes from '#routes'; | ||
|
||
interface ActivationParams { | ||
userId: string | undefined; | ||
token: string | undefined; | ||
[key: string]: string | undefined; | ||
} | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export function Component() { | ||
const { userId, token } = useParams<ActivationParams>(); | ||
const navigate = useNavigate(); | ||
|
||
const activationLink = (userId && token && routes.activation.path) ? ({ | ||
pathname: (generatePath(routes.activation.path, { userId, token })), | ||
}) | ||
: routes.pageNotFound.path; | ||
|
||
if (activationLink) { | ||
navigate(activationLink); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
Component.displayName = 'ActivationRedirect'; |
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,9 @@ | ||
{ | ||
"namespace": "activation", | ||
"strings": { | ||
"activationSuccessMessage":"Your account has been successfully activated!", | ||
"goToLogin":"Go to Login", | ||
"activationFailMessage":"An error occurred during activation. Please try again." | ||
} | ||
} | ||
|
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,103 @@ | ||
import { | ||
useEffect, | ||
useState, | ||
} from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { | ||
gql, | ||
useMutation, | ||
} from '@apollo/client'; | ||
import { Message } from '@ifrc-go/ui'; | ||
import { useTranslation } from '@ifrc-go/ui/hooks'; | ||
|
||
import Link from '#components/Link'; | ||
import Page from '#components/Page'; | ||
import useAlert from '#hooks/useAlert'; | ||
|
||
import i18n from './i18n.json'; | ||
import styles from './styles.module.css'; | ||
|
||
const ACCOUNT_ACTIVATION_MUTATION = gql` | ||
mutation AccountActivation($data: UserActivationInput!) { | ||
public { | ||
accountActivation(data: $data) { | ||
errors | ||
ok | ||
} | ||
} | ||
} | ||
`; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export function Component() { | ||
const { userId, token } = useParams<{ userId?: string, token?: string }>(); | ||
const alert = useAlert(); | ||
const strings = useTranslation(i18n); | ||
const [isErrored, setIsError] = useState(false); | ||
const [isSubmitted, setIsSubmitted] = useState(false); | ||
const [ | ||
activate, | ||
] = useMutation(ACCOUNT_ACTIVATION_MUTATION, { | ||
onCompleted: (response) => { | ||
const activateRes = response?.public?.accountActivation; | ||
if (!response) { | ||
return; | ||
} | ||
if (activateRes.ok) { | ||
setIsSubmitted(true); | ||
} else { | ||
setIsError(true); | ||
} | ||
}, | ||
onError: () => { | ||
alert.show( | ||
strings.activationFailMessage, | ||
{ variant: 'danger' }, | ||
); | ||
}, | ||
}); | ||
|
||
useEffect(() => { | ||
if (userId && token) { | ||
activate({ | ||
variables: { | ||
data: { | ||
uuid: userId, | ||
token, | ||
}, | ||
}, | ||
}); | ||
} | ||
}, [token, activate, userId]); | ||
|
||
if (isSubmitted) { | ||
return ( | ||
<Page> | ||
<Message | ||
title={strings.activationSuccessMessage} | ||
/> | ||
<div className={styles.activation}> | ||
<Link | ||
to="login" | ||
variant="primary" | ||
> | ||
{strings.goToLogin} | ||
</Link> | ||
</div> | ||
|
||
</Page> | ||
); | ||
} | ||
if (isErrored) { | ||
return ( | ||
<Page> | ||
<Message | ||
title={strings.activationFailMessage} | ||
/> | ||
</Page> | ||
); | ||
} | ||
return null; | ||
} | ||
|
||
Component.displayName = 'Activation'; |
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,8 @@ | ||
.activation { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--go-ui-spacing-xs); | ||
align-items: center; | ||
text-align: center; | ||
|
||
} |
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