diff options
author | 2021-03-07 18:48:43 +0200 | |
---|---|---|
committer | 2021-03-07 18:48:43 +0200 | |
commit | 11151894702fab1a06e3dfe9eca43d4596b5290e (patch) | |
tree | c74483bd5327751ef54a486d7bdcf20eed418919 /src/pages/FormPage.tsx | |
parent | Add margin to bottom of captcha (diff) | |
parent | Renables OAuth Button On Failure (diff) |
Merge branch 'main' into hcaptcha
Diffstat (limited to 'src/pages/FormPage.tsx')
-rw-r--r-- | src/pages/FormPage.tsx | 64 |
1 files changed, 30 insertions, 34 deletions
diff --git a/src/pages/FormPage.tsx b/src/pages/FormPage.tsx index 9ac26f1..2022d43 100644 --- a/src/pages/FormPage.tsx +++ b/src/pages/FormPage.tsx @@ -11,10 +11,12 @@ import HeaderBar from "../components/HeaderBar"; import RenderedQuestion from "../components/Question"; import Loading from "../components/Loading"; import ScrollToTop from "../components/ScrollToTop"; +import OAuth2Button from "../components/OAuth2Button"; import { Form, FormFeatures, getForm } from "../api/forms"; +import { OAuthScopes, checkScopes } from "../api/auth"; import colors from "../colors"; -import { unselectable } from "../commonStyles"; +import { submitStyles, unselectable } from "../commonStyles"; import { Question, QuestionType } from "../api/question"; import ApiClient from "../api/client"; @@ -23,7 +25,8 @@ interface PathParams { } interface NavigationProps { - form_state: boolean // Whether the form is open or not + form_state: boolean, // Whether the form is open or not + scopes: OAuthScopes[] } class Navigation extends React.Component<NavigationProps> { @@ -40,7 +43,7 @@ class Navigation extends React.Component<NavigationProps> { width: 50%; } - @media (max-width: 850px) { + @media (max-width: 870px) { width: 100%; > div { @@ -64,13 +67,13 @@ class Navigation extends React.Component<NavigationProps> { height: 0; display: none; - @media (max-width: 850px) { + @media (max-width: 870px) { display: block; } `; static returnStyles = css` - padding: 0.5rem 2rem; + padding: 0.5rem 2.2rem; border-radius: 8px; color: white; @@ -85,37 +88,23 @@ class Navigation extends React.Component<NavigationProps> { } `; - submitStyles = css` - text-align: right; - white-space: nowrap; - - button { - padding: 0.5rem 4rem; - cursor: pointer; - - border: none; - border-radius: 8px; - - color: white; - font: inherit; - - background-color: ${colors.blurple}; - transition: background-color 300ms; - } - - button:hover { - background-color: ${colors.darkerBlurple}; - } - `; + constructor(props: NavigationProps) { + super(props); + this.setState({"logged_in": false}); + } render(): JSX.Element { let submit = null; + if (this.props.form_state) { - submit = ( - <div css={this.submitStyles}> - <button form="form" type="submit">Submit</button> - </div> - ); + let inner_submit; + if (this.props.scopes.includes(OAuthScopes.Identify) && !checkScopes(this.props.scopes)) { + // Render OAuth button if login is required, and the scopes needed are not available + inner_submit = <OAuth2Button scopes={this.props.scopes} rerender={() => this.setState({"logged_in": true})}/>; + } else { + inner_submit = <button form="form" type="submit">Submit</button>; + } + submit = <div css={submitStyles}>{ inner_submit }</div>; } return ( @@ -149,7 +138,7 @@ const closedHeaderStyles = css` font-size: 1.5rem; background-color: ${colors.error}; - + @media (max-width: 500px) { padding: 1rem 1.5rem; } @@ -306,6 +295,13 @@ function FormPage(): JSX.Element { } const open: boolean = form.features.includes(FormFeatures.Open); + const require_auth: boolean = form.features.includes(FormFeatures.RequiresLogin); + + const scopes = []; + if (require_auth) { + scopes.push(OAuthScopes.Identify); + if (form.features.includes(FormFeatures.CollectEmail)) { scopes.push(OAuthScopes.Email); } + } let closed_header = null; if (!open) { @@ -341,7 +337,7 @@ function FormPage(): JSX.Element { { questions } </form> { captcha } - <Navigation form_state={open}/> + <Navigation form_state={open} scopes={scopes}/> </div> <div css={css`margin-bottom: 10rem`}/> |