From 343500e55aae6ae7909657990975c6d0780c11e1 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sun, 26 Mar 2023 12:26:07 +0200 Subject: [PATCH] feat: Add fields to AliasPreferencesForm.tsx --- public/locales/en-US/aliases.json | 4 +++ src/apis/update-alias.ts | 2 ++ src/apis/update-preferences.ts | 1 + .../AliasDetailRoute/AliasPreferencesForm.tsx | 30 +++++++++++++++-- .../AliasDetailRoute/SelectField.tsx | 3 ++ src/routes/SettingsAliasPreferencesRoute.tsx | 32 +++++++++++++++++++ src/server-types.ts | 2 ++ 7 files changed, 72 insertions(+), 2 deletions(-) diff --git a/public/locales/en-US/aliases.json b/public/locales/en-US/aliases.json index 832a2f7..74e829a 100644 --- a/public/locales/en-US/aliases.json +++ b/public/locales/en-US/aliases.json @@ -78,6 +78,10 @@ "expandUrlShorteners": { "label": "Expand URL Shorteners", "helperText": "Expand shortened URLs (for example bit.ly) to their original URL. This way those services can't track you." + }, + "rejectOnPrivacyLeak": { + "label": "Reject on Privacy Leak", + "helperText": "Reject emails that contain your email address. This happens especially often when you reply to emails. We recommend you to enable this feature." } } } diff --git a/src/apis/update-alias.ts b/src/apis/update-alias.ts index 691be68..0d90b8d 100644 --- a/src/apis/update-alias.ts +++ b/src/apis/update-alias.ts @@ -9,6 +9,8 @@ export interface UpdateAliasData { prefProxyImages?: boolean | null prefImagProxyFormat?: ImageProxyFormatType | null prefProxyUserAgent?: ProxyUserAgentType | null + prefExpandUrlShorteners?: boolean | null + prefRejectOnPrivacyLeak?: boolean | null } export default async function updateAlias(id: string, updateData: UpdateAliasData): Promise { diff --git a/src/apis/update-preferences.ts b/src/apis/update-preferences.ts index 360c9b5..c3b90f8 100644 --- a/src/apis/update-preferences.ts +++ b/src/apis/update-preferences.ts @@ -8,6 +8,7 @@ export interface UpdatePreferencesData { aliasImageProxyFormat?: ImageProxyFormatType aliasProxyUserAgent?: ProxyUserAgentType aliasExpandUrlShorteners?: boolean + aliasRejectOnPrivacyLeak?: boolean } export default async function updatePreferences( diff --git a/src/route-widgets/AliasDetailRoute/AliasPreferencesForm.tsx b/src/route-widgets/AliasDetailRoute/AliasPreferencesForm.tsx index cba250c..efc8dec 100644 --- a/src/route-widgets/AliasDetailRoute/AliasPreferencesForm.tsx +++ b/src/route-widgets/AliasDetailRoute/AliasPreferencesForm.tsx @@ -1,8 +1,8 @@ import * as yup from "yup" import {ReactElement, useContext} from "react" -import {BsImage, BsShieldShaded} from "react-icons/bs" +import {BsArrowsAngleExpand, BsImage, BsShieldShaded} from "react-icons/bs" import {useFormik} from "formik" -import {FaFile} from "react-icons/fa" +import {FaFile, FaHandPaper} from "react-icons/fa" import {MdCheckCircle, MdTextSnippet} from "react-icons/md" import {AxiosError} from "axios" import {useTranslation} from "react-i18next" @@ -32,6 +32,8 @@ interface Form { proxyImages: boolean | null imageProxyFormat: ImageProxyFormatType | null proxyUserAgent: ProxyUserAgentType | null + expandUrlShorteners: boolean | null + rejectOnPrivacyLeak: boolean | null detail?: string } @@ -78,6 +80,10 @@ export default function AliasPreferencesForm({ .mixed() .oneOf([true, false, null]) .label(t("settings.fields.expandUrlShorteners.label")), + rejectOnPrivacyLeak: yup + .mixed() + .oneOf([true, false, null]) + .label(t("settings.fields.rejectOnPrivacyLeak.label")), }) const {mutateAsync} = useMutation( @@ -108,6 +114,8 @@ export default function AliasPreferencesForm({ proxyImages: alias.prefProxyImages, imageProxyFormat: alias.prefImageProxyFormat, proxyUserAgent: alias.prefProxyUserAgent, + expandUrlShorteners: alias.prefExpandUrlShorteners, + rejectOnPrivacyLeak: alias.prefRejectOnPrivacyLeak, }, validationSchema: schema, onSubmit: async (values, {setErrors}) => { @@ -118,6 +126,8 @@ export default function AliasPreferencesForm({ prefProxyImages: values.proxyImages, prefImagProxyFormat: values.imageProxyFormat, prefProxyUserAgent: values.proxyUserAgent, + prefExpandUrlShorteners: values.expandUrlShorteners, + prefRejectOnPrivacyLeak: values.rejectOnPrivacyLeak, }) } catch (error) { setErrors(parseFastAPIError(error as AxiosError)) @@ -187,6 +197,22 @@ export default function AliasPreferencesForm({ + + } + name="expandUrlShorteners" + /> + + + } + name="rejectOnPrivacyLeak" + /> + diff --git a/src/route-widgets/AliasDetailRoute/SelectField.tsx b/src/route-widgets/AliasDetailRoute/SelectField.tsx index d4da56b..3490576 100644 --- a/src/route-widgets/AliasDetailRoute/SelectField.tsx +++ b/src/route-widgets/AliasDetailRoute/SelectField.tsx @@ -40,6 +40,9 @@ export default function SelectField({ const labelId = `${name}-label` const preferenceName = `alias${name.charAt(0).toUpperCase() + name.slice(1)}` const value = user.preferences[preferenceName as keyof User["preferences"]] + console.log(user.preferences) + console.log(preferenceName) + console.log(value) const defaultValueText = valueTextMap[value.toString()] return ( diff --git a/src/routes/SettingsAliasPreferencesRoute.tsx b/src/routes/SettingsAliasPreferencesRoute.tsx index 0dec109..bde40a9 100644 --- a/src/routes/SettingsAliasPreferencesRoute.tsx +++ b/src/routes/SettingsAliasPreferencesRoute.tsx @@ -35,6 +35,7 @@ interface Form { imageProxyFormat: ImageProxyFormatType proxyUserAgent: ProxyUserAgentType expandUrlShorteners: boolean + rejectOnPrivacyLeak: boolean detail?: string } @@ -69,6 +70,7 @@ export default function SettingsAliasPreferencesRoute(): ReactElement { .required() .label(t("settings.fields.proxyUserAgent.label")), expandUrlShorteners: yup.boolean().label(t("settings.fields.expandUrlShorteners.label")), + rejectOnPrivacyLeak: yup.boolean().label(t("settings.fields.rejectOnPrivacyLeak.label")), }) const {mutateAsync} = useMutation( @@ -101,6 +103,7 @@ export default function SettingsAliasPreferencesRoute(): ReactElement { imageProxyFormat: user.preferences.aliasImageProxyFormat, proxyUserAgent: user.preferences.aliasProxyUserAgent, expandUrlShorteners: user.preferences.aliasExpandUrlShorteners, + rejectOnPrivacyLeak: user.preferences.aliasRejectOnPrivacyLeak, }, onSubmit: async (values, {setErrors}) => { try { @@ -111,6 +114,7 @@ export default function SettingsAliasPreferencesRoute(): ReactElement { aliasImageProxyFormat: values.imageProxyFormat, aliasProxyUserAgent: values.proxyUserAgent, aliasExpandUrlShorteners: values.expandUrlShorteners, + aliasRejectOnPrivacyLeak: values.rejectOnPrivacyLeak, }) } catch (error) { setErrors(parseFastAPIError(error as AxiosError)) @@ -349,6 +353,34 @@ export default function SettingsAliasPreferencesRoute(): ReactElement { + + + + } + labelPlacement="start" + label={t("settings.fields.rejectOnPrivacyLeak.label")} + /> + + {(formik.touched.rejectOnPrivacyLeak && + formik.errors.rejectOnPrivacyLeak) || + t("settings.fields.rejectOnPrivacyLeak.helperText")} + + +