From 6345e21db96dd27bb9fe7d628a1486fe0e93e41e Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Mon, 13 Mar 2023 08:50:54 +0100 Subject: [PATCH] refactor: globalize modal title style --- backend/src/share/share.service.ts | 2 +- .../account/showEnableTotpModal.tsx | 3 +- .../admin/users/showCreateUserModal.tsx | 3 +- .../admin/users/showUpdateUserModal.tsx | 3 +- .../modals/showCompletedReverseShareModal.tsx | 8 +-- .../modals/showCreateReverseShareModal.tsx | 3 +- .../share/showEnterPasswordModal.tsx | 69 +++++++++---------- .../src/components/share/showErrorModal.tsx | 4 +- .../modals/showCompletedUploadModal.tsx | 15 +--- .../upload/modals/showCreateUploadModal.tsx | 2 +- frontend/src/pages/share/[shareId]/index.tsx | 6 +- frontend/src/styles/mantine.style.ts | 10 +++ 12 files changed, 59 insertions(+), 69 deletions(-) diff --git a/backend/src/share/share.service.ts b/backend/src/share/share.service.ts index 321e1559..4a46c280 100644 --- a/backend/src/share/share.service.ts +++ b/backend/src/share/share.service.ts @@ -278,7 +278,7 @@ export class ShareService { share?.security?.password && !(await argon.verify(share.security.password, password)) ) { - throw new ForbiddenException("Wrong password"); + throw new ForbiddenException("Wrong password", "wrong_password"); } if (share.security?.maxViews && share.security.maxViews <= share.views) { diff --git a/frontend/src/components/account/showEnableTotpModal.tsx b/frontend/src/components/account/showEnableTotpModal.tsx index 4bacaa59..2073236e 100644 --- a/frontend/src/components/account/showEnableTotpModal.tsx +++ b/frontend/src/components/account/showEnableTotpModal.tsx @@ -7,7 +7,6 @@ import { Stack, Text, TextInput, - Title, Tooltip, } from "@mantine/core"; import { useForm, yupResolver } from "@mantine/form"; @@ -27,7 +26,7 @@ const showEnableTotpModal = ( } ) => { return modals.openModal({ - title: Enable TOTP, + title: "Enable TOTP", children: ( ), diff --git a/frontend/src/components/admin/users/showCreateUserModal.tsx b/frontend/src/components/admin/users/showCreateUserModal.tsx index 727b0a35..cf6a094b 100644 --- a/frontend/src/components/admin/users/showCreateUserModal.tsx +++ b/frontend/src/components/admin/users/showCreateUserModal.tsx @@ -5,7 +5,6 @@ import { Stack, Switch, TextInput, - Title, } from "@mantine/core"; import { useForm, yupResolver } from "@mantine/form"; import { ModalsContextProps } from "@mantine/modals/lib/context"; @@ -19,7 +18,7 @@ const showCreateUserModal = ( getUsers: () => void ) => { return modals.openModal({ - title: Create user, + title: "Create user", children: ( ), diff --git a/frontend/src/components/admin/users/showUpdateUserModal.tsx b/frontend/src/components/admin/users/showUpdateUserModal.tsx index c15338e1..c3a24324 100644 --- a/frontend/src/components/admin/users/showUpdateUserModal.tsx +++ b/frontend/src/components/admin/users/showUpdateUserModal.tsx @@ -6,7 +6,6 @@ import { Stack, Switch, TextInput, - Title, } from "@mantine/core"; import { useForm, yupResolver } from "@mantine/form"; import { ModalsContextProps } from "@mantine/modals/lib/context"; @@ -21,7 +20,7 @@ const showUpdateUserModal = ( getUsers: () => void ) => { return modals.openModal({ - title: Update {user.username}, + title: `Update ${user.username}`, children: , }); }; diff --git a/frontend/src/components/share/modals/showCompletedReverseShareModal.tsx b/frontend/src/components/share/modals/showCompletedReverseShareModal.tsx index b79565bc..54a872ac 100644 --- a/frontend/src/components/share/modals/showCompletedReverseShareModal.tsx +++ b/frontend/src/components/share/modals/showCompletedReverseShareModal.tsx @@ -1,4 +1,4 @@ -import { ActionIcon, Button, Stack, TextInput, Title } from "@mantine/core"; +import { ActionIcon, Button, Stack, TextInput } from "@mantine/core"; import { useClipboard } from "@mantine/hooks"; import { useModals } from "@mantine/modals"; import { ModalsContextProps } from "@mantine/modals/lib/context"; @@ -14,11 +14,7 @@ const showCompletedReverseShareModal = ( closeOnClickOutside: false, withCloseButton: false, closeOnEscape: false, - title: ( - - Reverse share link - - ), + title: "Reverse share link", children: , }); }; diff --git a/frontend/src/components/share/modals/showCreateReverseShareModal.tsx b/frontend/src/components/share/modals/showCreateReverseShareModal.tsx index 0c00b869..590df228 100644 --- a/frontend/src/components/share/modals/showCreateReverseShareModal.tsx +++ b/frontend/src/components/share/modals/showCreateReverseShareModal.tsx @@ -8,7 +8,6 @@ import { Stack, Switch, Text, - Title, } from "@mantine/core"; import { useForm } from "@mantine/form"; import { useModals } from "@mantine/modals"; @@ -25,7 +24,7 @@ const showCreateReverseShareModal = ( getReverseShares: () => void ) => { return modals.openModal({ - title: Create reverse share, + title: "Create reverse share", children: ( Promise ) => { return modals.openModal({ closeOnClickOutside: false, withCloseButton: false, closeOnEscape: false, - title: ( - <> - Password required - - This access this share please enter the password for the share. - - - ), + title: "Password required", children: , }); }; -const Body = ({ submitCallback }: { submitCallback: any }) => { +const Body = ({ + submitCallback, +}: { + submitCallback: (password: string) => Promise; +}) => { const [password, setPassword] = useState(""); const [passwordWrong, setPasswordWrong] = useState(false); return ( - <> - - setPasswordWrong(false)} - onChange={(e) => setPassword(e.target.value)} - value={password} - /> - - - + + + This access this share please enter the password for the share. + + +
{ + e.preventDefault(); + submitCallback(password); + }} + > + + setPasswordWrong(false)} + onChange={(e) => setPassword(e.target.value)} + value={password} + /> + + +
+
); }; diff --git a/frontend/src/components/share/showErrorModal.tsx b/frontend/src/components/share/showErrorModal.tsx index c0c27831..72f01719 100644 --- a/frontend/src/components/share/showErrorModal.tsx +++ b/frontend/src/components/share/showErrorModal.tsx @@ -1,4 +1,4 @@ -import { Button, Stack, Text, Title } from "@mantine/core"; +import { Button, Stack, Text } from "@mantine/core"; import { useModals } from "@mantine/modals"; import { ModalsContextProps } from "@mantine/modals/lib/context"; import { useRouter } from "next/router"; @@ -12,7 +12,7 @@ const showErrorModal = ( closeOnClickOutside: false, withCloseButton: false, closeOnEscape: false, - title: {title}, + title: title, children: , }); diff --git a/frontend/src/components/upload/modals/showCompletedUploadModal.tsx b/frontend/src/components/upload/modals/showCompletedUploadModal.tsx index a03ed9ea..43c5fd18 100644 --- a/frontend/src/components/upload/modals/showCompletedUploadModal.tsx +++ b/frontend/src/components/upload/modals/showCompletedUploadModal.tsx @@ -1,11 +1,4 @@ -import { - ActionIcon, - Button, - Stack, - Text, - TextInput, - Title, -} from "@mantine/core"; +import { ActionIcon, Button, Stack, Text, TextInput } from "@mantine/core"; import { useClipboard } from "@mantine/hooks"; import { useModals } from "@mantine/modals"; import { ModalsContextProps } from "@mantine/modals/lib/context"; @@ -24,11 +17,7 @@ const showCompletedUploadModal = ( closeOnClickOutside: false, withCloseButton: false, closeOnEscape: false, - title: ( - - Share ready - - ), + title: "Share ready", children: , }); }; diff --git a/frontend/src/components/upload/modals/showCreateUploadModal.tsx b/frontend/src/components/upload/modals/showCreateUploadModal.tsx index 41315ab5..c9f5901f 100644 --- a/frontend/src/components/upload/modals/showCreateUploadModal.tsx +++ b/frontend/src/components/upload/modals/showCreateUploadModal.tsx @@ -37,7 +37,7 @@ const showCreateUploadModal = ( uploadCallback: (createShare: CreateShare) => void ) => { return modals.openModal({ - title: Share, + title: "Share", children: ( { getFiles(); }) .catch((e) => { - if (e.response.data.error == "share_max_views_exceeded") { + const { error } = e.response.data; + if (error == "share_max_views_exceeded") { showErrorModal( modals, "Visitor limit exceeded", "The visitor limit from this share has been exceeded." ); + } else { + toast.axiosError(e); } }); }; diff --git a/frontend/src/styles/mantine.style.ts b/frontend/src/styles/mantine.style.ts index 510c7d35..005c21b9 100644 --- a/frontend/src/styles/mantine.style.ts +++ b/frontend/src/styles/mantine.style.ts @@ -16,4 +16,14 @@ export default { ], }, primaryColor: "victoria", + components: { + Modal: { + styles: (theme) => ({ + title: { + fontSize: theme.fontSizes.lg, + fontWeight: 700, + }, + }), + }, + }, };