Skip to content

feat: specify a custom "terms of service" link #13068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bep
  • Loading branch information
aslilac committed Apr 25, 2024
commit d3ec782c0ad37e2db3f026ff8f0a32a905d97301
4 changes: 4 additions & 0 deletions site/src/pages/LoginPage/LoginPageView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import {
MockAuthMethodsExternal,
MockAuthMethodsPasswordOnly,
MockAuthMethodsPasswordTermsOfService,
MockBuildInfo,
mockApiError,
} from "testHelpers/entities";
import { LoginPageView } from "./LoginPageView";

const meta: Meta<typeof LoginPageView> = {
title: "pages/LoginPage",
component: LoginPageView,
args: {
buildInfo: MockBuildInfo,
},
};

export default meta;
Expand Down
15 changes: 15 additions & 0 deletions site/src/pages/LoginPage/LoginPageView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Interpolation, Theme } from "@emotion/react";
import Link from "@mui/material/Link";
import type { FC } from "react";
import { useLocation } from "react-router-dom";
import type { AuthMethods, BuildInfoResponse } from "api/typesGenerated";
Expand Down Expand Up @@ -70,6 +71,20 @@ export const LoginPageView: FC<LoginPageViewProps> = ({
Copyright &copy; {new Date().getFullYear()} Coder Technologies, Inc.
</div>
<div>{buildInfo?.version}</div>

{authMethods?.terms_of_service_link && (
<div css={{ paddingTop: 12, fontSize: 12 }}>
By continuing, you agree to the{" "}
<Link
href={authMethods.terms_of_service_link}
target="_blank"
rel="noreferrer"
>
Terms of Service
</Link>
.
</div>
)}
</footer>
</div>
</div>
Expand Down
71 changes: 20 additions & 51 deletions site/src/pages/LoginPage/SignInForm.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { Interpolation, Theme } from "@emotion/react";
import Checkbox from "@mui/material/Checkbox";
import { type FC, type ReactNode, useState } from "react";
import type { FC, ReactNode } from "react";
import type { AuthMethods } from "api/typesGenerated";
import { Alert } from "components/Alert/Alert";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import { getApplicationName } from "utils/appearance";
import { OAuthSignInForm } from "./OAuthSignInForm";
import { PasswordSignInForm } from "./PasswordSignInForm";
import { Link } from "@mui/material";

export const Language = {
emailLabel: "Email",
Expand Down Expand Up @@ -85,10 +83,6 @@ export const SignInForm: FC<SignInFormProps> = ({
const passwordEnabled = authMethods?.password.enabled ?? true;
const applicationName = getApplicationName();

const [tosAccepted, setTosAccepted] = useState(false);
const termsOfServiceAcceptanceRequired =
authMethods?.terms_of_service_link && !tosAccepted;

return (
<div css={styles.root}>
<h1 css={styles.title}>{applicationName}</h1>
Expand All @@ -105,55 +99,30 @@ export const SignInForm: FC<SignInFormProps> = ({
</div>
)}

{!termsOfServiceAcceptanceRequired && (
<>
{oAuthEnabled && (
<OAuthSignInForm
isSigningIn={isSigningIn}
redirectTo={redirectTo}
authMethods={authMethods}
/>
)}

{passwordEnabled && oAuthEnabled && (
<div css={styles.divider}>
<div css={styles.dividerLine} />
<div css={styles.dividerLabel}>or</div>
<div css={styles.dividerLine} />
</div>
)}

{passwordEnabled && (
<PasswordSignInForm
onSubmit={onSubmit}
autoFocus={!oAuthEnabled}
isSigningIn={isSigningIn}
/>
)}
</>
{oAuthEnabled && (
<OAuthSignInForm
isSigningIn={isSigningIn}
redirectTo={redirectTo}
authMethods={authMethods}
/>
)}

{authMethods?.terms_of_service_link && (
<div css={{ paddingTop: 8, fontSize: 14 }}>
<label>
<Checkbox
size="small"
checked={tosAccepted}
onChange={(event) => setTosAccepted(event.target.checked)}
/>
I agree to the{" "}
<Link
href={authMethods.terms_of_service_link}
target="_blank"
rel="noreferrer"
>
Terms of Service
</Link>
.
</label>
{passwordEnabled && oAuthEnabled && (
<div css={styles.divider}>
<div css={styles.dividerLine} />
<div css={styles.dividerLabel}>or</div>
<div css={styles.dividerLine} />
</div>
)}

{passwordEnabled && (
<PasswordSignInForm
onSubmit={onSubmit}
autoFocus={!oAuthEnabled}
isSigningIn={isSigningIn}
/>
)}

{!passwordEnabled && !oAuthEnabled && (
<Alert severity="error">No authentication methods configured!</Alert>
)}
Expand Down
Loading