Skip to content

Commit

Permalink
Handle errors in feide auth
Browse files Browse the repository at this point in the history
  • Loading branch information
LudvigHz committed Aug 6, 2023
1 parent 571d134 commit 8cf213f
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions app/routes/users/components/StudentConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import Card from 'app/components/Card';
import { Button } from 'app/components/Form';
import { Container, Flex } from 'app/components/Layout';
import Modal from 'app/components/Modal';
import type { CurrentUser } from 'app/store/models/User';
import styles from './UserConfirmation.css';

type Props = {
studentConfirmed: boolean;
loggedIn: boolean;
submitSucceeded: () => void;
startStudentAuth: () => Promise<void>;
confirmStudentAuth: (options: {
code: string;
state: string;
}) => Promise<void>;
updateUser: () => Promise<void>;
currentUser: CurrentUser;
isStudent: boolean;
};

Expand All @@ -32,8 +37,8 @@ const NotEligibleInfo = () => (
</li>
<li>
Sende en mail til <a href="mailto:abakus@abakus.no">abakus@abakus.no</a>{' '}
med søknad om hvorfor du ønsker å bli medlem av Abakus. (Det trenger
ikke være en stor søknad :))
med søknad om hvorfor du ønsker å bli medlem av Abakus. Det trenger ikke
være en stor søknad :)
</li>
</ol>
</div>
Expand Down Expand Up @@ -70,8 +75,12 @@ const StudentConfirmation = ({
useEffect(() => {
const validateStudentAuth = async () => {
if (code && state) {
const res = await confirmStudentAuth({ code, state });
setAuthRes(res.payload);
try {
const res = await confirmStudentAuth({ code, state });
setAuthRes(res.payload);
} catch (e) {
setAuthRes(e.payload.response.jsonData);
}
history.replace({ search: '' });
}
};
Expand All @@ -88,7 +97,7 @@ const StudentConfirmation = ({
<div>
<h2>Verifiser studentstatus</h2>

{isStudent == null && (
{isStudent === null && (
<p>
For å kunne bli medlem i Abakus og få mulighet til å delta på
arrangementer, få tilgang til bilder og interessegrupper og mer må
Expand All @@ -99,7 +108,7 @@ const StudentConfirmation = ({
</p>
)}

{isStudent != null &&
{isStudent !== null &&
(isStudent ? (
<Card info>
<h4>Du er verifisert som student</h4>
Expand All @@ -121,14 +130,14 @@ const StudentConfirmation = ({
) : (
<Card danger>
<h4>
Informasjon vi har hentet om deg fra StudentWeb gir ikke
Informasjonen vi har hentet om deg fra StudentWeb gir ikke
mulighet for automatisk medlemskap i Abakus
</h4>
<NotEligibleInfo />
</Card>
))}

{authRes && !isStudent && (
{authRes && authRes.status !== 'success' && (
<Card danger={authRes.status !== 'success'}>
{authRes.status === 'unauthorized' && (
<>
Expand All @@ -143,13 +152,19 @@ const StudentConfirmation = ({
<NotEligibleInfo />
</>
)}
{authRes.status === 'error' && (
<>
<h4>En feil oppsto under validering av din studentstatus:</h4>
<p>{authRes.detail}</p>
</>
)}
</Card>
)}

<Button success onClick={() => performStudentAuth()}>
Verifiser med FEIDE
</Button>
{isStudent != null && (
{isStudent !== null && (
<p className={styles.infoText}>
Du har allerede verifisert din status. Dersom du har byttet studie
og ønsker å bli medlem av Abakus, kan du verifisere deg på nytt og
Expand All @@ -167,7 +182,7 @@ const StudentConfirmation = ({
<Flex column>
<h4>Din studentstatus ble godkjent!</h4>
<p>
Du har blitt satt i gruppen: <b>{authRes?.grade}</b>
Du har blitt satt i gruppen <b>{authRes?.grade}</b>
</p>
</Flex>
</Card>
Expand All @@ -178,14 +193,7 @@ const StudentConfirmation = ({
Datateknologi kan bli medlem av Abakus. Du må bli medlem for å
kunne delta på arrangementer, kurs og annet Abakus tilbyr. Vi
anbefaler alle nye studenter å melde seg inn. Du kan lese mer om{' '}
<a
href="https://abakus.no/pages/info-om-abakus"
rel="noopener noreferrer"
target="_blank"
>
Abakus
</a>{' '}
og{' '}
<Link to="/pages/info-om-abakus">Abakus</Link> og{' '}
<a
href="https://statutter.abakus.no#medlemskap"
rel="noopener noreferrer"
Expand All @@ -201,7 +209,7 @@ const StudentConfirmation = ({
</p>
</div>

<Flex row>
<Flex>
<Button dark onClick={() => setAbakusMember(false)}>
Jeg vil ikke bli medlem
</Button>
Expand Down

0 comments on commit 8cf213f

Please sign in to comment.