From 7841fadcb6050601b865803f4844ae653b39caee Mon Sep 17 00:00:00 2001 From: mrjvs Date: Sat, 2 Dec 2023 00:02:09 +0100 Subject: [PATCH] make email an optional setting + add device name validation --- src/assets/locales/en.json | 1 + src/components/layout/Footer.tsx | 3 +++ src/pages/Dmca.tsx | 8 ++++++-- src/pages/parts/auth/AccountCreatePart.tsx | 16 ++++++++++++++-- src/pages/parts/auth/LoginFormPart.tsx | 9 ++++++--- src/setup/App.tsx | 7 +++++-- src/setup/config.ts | 5 +++++ 7 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/assets/locales/en.json b/src/assets/locales/en.json index 78653fed..d4adb9a1 100644 --- a/src/assets/locales/en.json +++ b/src/assets/locales/en.json @@ -16,6 +16,7 @@ "title": "Login to your account", "description": "Please enter your passphrase to login to your account", "validationError": "Invalid or incomplete passphrase", + "deviceLengthError": "Please entire a device name", "submit": "Login", "passphraseLabel": "12-Word passphrase", "passphrasePlaceholder": "Passphrase" diff --git a/src/components/layout/Footer.tsx b/src/components/layout/Footer.tsx index 3704c446..ec4951a6 100644 --- a/src/components/layout/Footer.tsx +++ b/src/components/layout/Footer.tsx @@ -4,6 +4,7 @@ import { useHistory } from "react-router-dom"; import { Icon, Icons } from "@/components/Icon"; import { BrandPill } from "@/components/layout/BrandPill"; import { WideContainer } from "@/components/layout/WideContainer"; +import { shouldHaveDmcaPage } from "@/pages/Dmca"; import { conf } from "@/setup/config"; function FooterLink(props: { @@ -30,6 +31,8 @@ function Dmca() { const { t } = useTranslation(); const history = useHistory(); + if (!shouldHaveDmcaPage()) return null; + return ( history.push("/dmca")}> {t("footer.links.dmca")} diff --git a/src/pages/Dmca.tsx b/src/pages/Dmca.tsx index 4aff3985..d0ceebd3 100644 --- a/src/pages/Dmca.tsx +++ b/src/pages/Dmca.tsx @@ -4,10 +4,14 @@ import { Icon, Icons } from "@/components/Icon"; import { ThinContainer } from "@/components/layout/ThinContainer"; import { Heading1, Paragraph } from "@/components/utils/Text"; import { PageTitle } from "@/pages/parts/util/PageTitle"; +import { conf } from "@/setup/config"; import { SubPageLayout } from "./layouts/SubPageLayout"; -// TODO make email a constant +export function shouldHaveDmcaPage() { + return !!conf().DMCA_EMAIL; +} + export function DmcaPage() { const { t } = useTranslation(); @@ -19,7 +23,7 @@ export function DmcaPage() { {t("screens.dmca.text")} - dmca@movie-web.app + {conf().DMCA_EMAIL ?? ""} diff --git a/src/pages/parts/auth/AccountCreatePart.tsx b/src/pages/parts/auth/AccountCreatePart.tsx index 3de705f7..7fa90ff7 100644 --- a/src/pages/parts/auth/AccountCreatePart.tsx +++ b/src/pages/parts/auth/AccountCreatePart.tsx @@ -32,11 +32,18 @@ export function AccountCreatePart(props: AccountCreatePartProps) { const [colorB, setColorB] = useState("#2E65CF"); const [userIcon, setUserIcon] = useState(UserIcons.USER); const { t } = useTranslation(); - // TODO validate device and account before next step + const [hasDeviceError, setHasDeviceError] = useState(false); const nextStep = useCallback(() => { + setHasDeviceError(false); + const validatedDevice = device.trim(); + if (validatedDevice.length === 0) { + setHasDeviceError(true); + return; + } + props.onNext?.({ - device, + device: validatedDevice, profile: { colorA, colorB, @@ -75,6 +82,11 @@ export function AccountCreatePart(props: AccountCreatePartProps) { value={userIcon} onInput={setUserIcon} /> + {hasDeviceError ? ( +

+ {t("auth.login.deviceLengthError")} +

+ ) : null}