aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages/FormPage/Navigation.tsx
blob: 20c7dce5d241a343c06be5b25396d21d19c691e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/** @jsx jsx */
import {jsx} from "@emotion/react";
import React, {useState} from "react";
import {Link} from "react-router-dom";

import * as styles from "../../commonStyles";
import {checkScopes, OAuthScopes} from "../../api/auth";
import OAuth2Button from "../../components/OAuth2Button";


interface NavigationProps {
    form_state: boolean,  // Whether the form is open or not
    scopes: OAuthScopes[]
}

export default function Navigation(props: NavigationProps): JSX.Element {
    const [authorized, setAuth] = useState<boolean>(!(
        props.scopes.includes(OAuthScopes.Identify) && !checkScopes(props.scopes)
    ));

    let submit = null;
    if (props.form_state) {
        let innerElement;
        if (!authorized) {
            innerElement = <OAuth2Button rerender={() => setAuth(true)} scopes={props.scopes}/>;
        } else {
            innerElement = <button form="form" type="submit">Submit</button>;
        }
        submit = <div css={styles.actionButtonStyles}>{innerElement}</div>;
    }

    return (
        <div css={[styles.unselectable, styles.mainTextStyles]}>
            <div css={styles.navigationStyles}>
                <Link to="/" css={styles.returnButtonStyles}>Return Home</Link>
                { submit }
            </div>
        </div>
    );
}