mirror of
https://github.com/Myzel394/kleckrelay-website.git
synced 2025-06-18 15:35:26 +02:00
feat: Add fields to AliasPreferencesForm.tsx
This commit is contained in:
parent
4f3ff28e34
commit
343500e55a
@ -78,6 +78,10 @@
|
|||||||
"expandUrlShorteners": {
|
"expandUrlShorteners": {
|
||||||
"label": "Expand URL Shorteners",
|
"label": "Expand URL Shorteners",
|
||||||
"helperText": "Expand shortened URLs (for example bit.ly) to their original URL. This way those services can't track you."
|
"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."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ export interface UpdateAliasData {
|
|||||||
prefProxyImages?: boolean | null
|
prefProxyImages?: boolean | null
|
||||||
prefImagProxyFormat?: ImageProxyFormatType | null
|
prefImagProxyFormat?: ImageProxyFormatType | null
|
||||||
prefProxyUserAgent?: ProxyUserAgentType | null
|
prefProxyUserAgent?: ProxyUserAgentType | null
|
||||||
|
prefExpandUrlShorteners?: boolean | null
|
||||||
|
prefRejectOnPrivacyLeak?: boolean | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function updateAlias(id: string, updateData: UpdateAliasData): Promise<Alias> {
|
export default async function updateAlias(id: string, updateData: UpdateAliasData): Promise<Alias> {
|
||||||
|
@ -8,6 +8,7 @@ export interface UpdatePreferencesData {
|
|||||||
aliasImageProxyFormat?: ImageProxyFormatType
|
aliasImageProxyFormat?: ImageProxyFormatType
|
||||||
aliasProxyUserAgent?: ProxyUserAgentType
|
aliasProxyUserAgent?: ProxyUserAgentType
|
||||||
aliasExpandUrlShorteners?: boolean
|
aliasExpandUrlShorteners?: boolean
|
||||||
|
aliasRejectOnPrivacyLeak?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function updatePreferences(
|
export default async function updatePreferences(
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import * as yup from "yup"
|
import * as yup from "yup"
|
||||||
import {ReactElement, useContext} from "react"
|
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 {useFormik} from "formik"
|
||||||
import {FaFile} from "react-icons/fa"
|
import {FaFile, FaHandPaper} from "react-icons/fa"
|
||||||
import {MdCheckCircle, MdTextSnippet} from "react-icons/md"
|
import {MdCheckCircle, MdTextSnippet} from "react-icons/md"
|
||||||
import {AxiosError} from "axios"
|
import {AxiosError} from "axios"
|
||||||
import {useTranslation} from "react-i18next"
|
import {useTranslation} from "react-i18next"
|
||||||
@ -32,6 +32,8 @@ interface Form {
|
|||||||
proxyImages: boolean | null
|
proxyImages: boolean | null
|
||||||
imageProxyFormat: ImageProxyFormatType | null
|
imageProxyFormat: ImageProxyFormatType | null
|
||||||
proxyUserAgent: ProxyUserAgentType | null
|
proxyUserAgent: ProxyUserAgentType | null
|
||||||
|
expandUrlShorteners: boolean | null
|
||||||
|
rejectOnPrivacyLeak: boolean | null
|
||||||
|
|
||||||
detail?: string
|
detail?: string
|
||||||
}
|
}
|
||||||
@ -78,6 +80,10 @@ export default function AliasPreferencesForm({
|
|||||||
.mixed<boolean | null>()
|
.mixed<boolean | null>()
|
||||||
.oneOf([true, false, null])
|
.oneOf([true, false, null])
|
||||||
.label(t("settings.fields.expandUrlShorteners.label")),
|
.label(t("settings.fields.expandUrlShorteners.label")),
|
||||||
|
rejectOnPrivacyLeak: yup
|
||||||
|
.mixed<boolean | null>()
|
||||||
|
.oneOf([true, false, null])
|
||||||
|
.label(t("settings.fields.rejectOnPrivacyLeak.label")),
|
||||||
})
|
})
|
||||||
|
|
||||||
const {mutateAsync} = useMutation<Alias, AxiosError, UpdateAliasData>(
|
const {mutateAsync} = useMutation<Alias, AxiosError, UpdateAliasData>(
|
||||||
@ -108,6 +114,8 @@ export default function AliasPreferencesForm({
|
|||||||
proxyImages: alias.prefProxyImages,
|
proxyImages: alias.prefProxyImages,
|
||||||
imageProxyFormat: alias.prefImageProxyFormat,
|
imageProxyFormat: alias.prefImageProxyFormat,
|
||||||
proxyUserAgent: alias.prefProxyUserAgent,
|
proxyUserAgent: alias.prefProxyUserAgent,
|
||||||
|
expandUrlShorteners: alias.prefExpandUrlShorteners,
|
||||||
|
rejectOnPrivacyLeak: alias.prefRejectOnPrivacyLeak,
|
||||||
},
|
},
|
||||||
validationSchema: schema,
|
validationSchema: schema,
|
||||||
onSubmit: async (values, {setErrors}) => {
|
onSubmit: async (values, {setErrors}) => {
|
||||||
@ -118,6 +126,8 @@ export default function AliasPreferencesForm({
|
|||||||
prefProxyImages: values.proxyImages,
|
prefProxyImages: values.proxyImages,
|
||||||
prefImagProxyFormat: values.imageProxyFormat,
|
prefImagProxyFormat: values.imageProxyFormat,
|
||||||
prefProxyUserAgent: values.proxyUserAgent,
|
prefProxyUserAgent: values.proxyUserAgent,
|
||||||
|
prefExpandUrlShorteners: values.expandUrlShorteners,
|
||||||
|
prefRejectOnPrivacyLeak: values.rejectOnPrivacyLeak,
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setErrors(parseFastAPIError(error as AxiosError))
|
setErrors(parseFastAPIError(error as AxiosError))
|
||||||
@ -187,6 +197,22 @@ export default function AliasPreferencesForm({
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Grid item xs={12} sm={6}>
|
||||||
|
<SelectField
|
||||||
|
label={t("settings.fields.expandUrlShorteners.label")}
|
||||||
|
formik={formik}
|
||||||
|
icon={<BsArrowsAngleExpand />}
|
||||||
|
name="expandUrlShorteners"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={12} sm={6}>
|
||||||
|
<SelectField
|
||||||
|
label={t("settings.fields.rejectOnPrivacyLeak.label")}
|
||||||
|
formik={formik}
|
||||||
|
icon={<FaHandPaper />}
|
||||||
|
name="rejectOnPrivacyLeak"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item>
|
<Grid item>
|
||||||
|
@ -40,6 +40,9 @@ export default function SelectField({
|
|||||||
const labelId = `${name}-label`
|
const labelId = `${name}-label`
|
||||||
const preferenceName = `alias${name.charAt(0).toUpperCase() + name.slice(1)}`
|
const preferenceName = `alias${name.charAt(0).toUpperCase() + name.slice(1)}`
|
||||||
const value = user.preferences[preferenceName as keyof User["preferences"]]
|
const value = user.preferences[preferenceName as keyof User["preferences"]]
|
||||||
|
console.log(user.preferences)
|
||||||
|
console.log(preferenceName)
|
||||||
|
console.log(value)
|
||||||
const defaultValueText = valueTextMap[value.toString()]
|
const defaultValueText = valueTextMap[value.toString()]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -35,6 +35,7 @@ interface Form {
|
|||||||
imageProxyFormat: ImageProxyFormatType
|
imageProxyFormat: ImageProxyFormatType
|
||||||
proxyUserAgent: ProxyUserAgentType
|
proxyUserAgent: ProxyUserAgentType
|
||||||
expandUrlShorteners: boolean
|
expandUrlShorteners: boolean
|
||||||
|
rejectOnPrivacyLeak: boolean
|
||||||
|
|
||||||
detail?: string
|
detail?: string
|
||||||
}
|
}
|
||||||
@ -69,6 +70,7 @@ export default function SettingsAliasPreferencesRoute(): ReactElement {
|
|||||||
.required()
|
.required()
|
||||||
.label(t("settings.fields.proxyUserAgent.label")),
|
.label(t("settings.fields.proxyUserAgent.label")),
|
||||||
expandUrlShorteners: yup.boolean().label(t("settings.fields.expandUrlShorteners.label")),
|
expandUrlShorteners: yup.boolean().label(t("settings.fields.expandUrlShorteners.label")),
|
||||||
|
rejectOnPrivacyLeak: yup.boolean().label(t("settings.fields.rejectOnPrivacyLeak.label")),
|
||||||
})
|
})
|
||||||
|
|
||||||
const {mutateAsync} = useMutation<SimpleDetailResponse, AxiosError, UpdatePreferencesData>(
|
const {mutateAsync} = useMutation<SimpleDetailResponse, AxiosError, UpdatePreferencesData>(
|
||||||
@ -101,6 +103,7 @@ export default function SettingsAliasPreferencesRoute(): ReactElement {
|
|||||||
imageProxyFormat: user.preferences.aliasImageProxyFormat,
|
imageProxyFormat: user.preferences.aliasImageProxyFormat,
|
||||||
proxyUserAgent: user.preferences.aliasProxyUserAgent,
|
proxyUserAgent: user.preferences.aliasProxyUserAgent,
|
||||||
expandUrlShorteners: user.preferences.aliasExpandUrlShorteners,
|
expandUrlShorteners: user.preferences.aliasExpandUrlShorteners,
|
||||||
|
rejectOnPrivacyLeak: user.preferences.aliasRejectOnPrivacyLeak,
|
||||||
},
|
},
|
||||||
onSubmit: async (values, {setErrors}) => {
|
onSubmit: async (values, {setErrors}) => {
|
||||||
try {
|
try {
|
||||||
@ -111,6 +114,7 @@ export default function SettingsAliasPreferencesRoute(): ReactElement {
|
|||||||
aliasImageProxyFormat: values.imageProxyFormat,
|
aliasImageProxyFormat: values.imageProxyFormat,
|
||||||
aliasProxyUserAgent: values.proxyUserAgent,
|
aliasProxyUserAgent: values.proxyUserAgent,
|
||||||
aliasExpandUrlShorteners: values.expandUrlShorteners,
|
aliasExpandUrlShorteners: values.expandUrlShorteners,
|
||||||
|
aliasRejectOnPrivacyLeak: values.rejectOnPrivacyLeak,
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setErrors(parseFastAPIError(error as AxiosError))
|
setErrors(parseFastAPIError(error as AxiosError))
|
||||||
@ -349,6 +353,34 @@ export default function SettingsAliasPreferencesRoute(): ReactElement {
|
|||||||
</Alert>
|
</Alert>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<FormGroup>
|
||||||
|
<FormControlLabel
|
||||||
|
disabled={formik.isSubmitting}
|
||||||
|
control={
|
||||||
|
<Checkbox
|
||||||
|
name="rejectOnPrivacyLeak"
|
||||||
|
id="rejectOnPrivacyLeak"
|
||||||
|
checked={formik.values.rejectOnPrivacyLeak}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
onBlur={formik.handleBlur}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
labelPlacement="start"
|
||||||
|
label={t("settings.fields.rejectOnPrivacyLeak.label")}
|
||||||
|
/>
|
||||||
|
<FormHelperText
|
||||||
|
error={Boolean(
|
||||||
|
formik.touched.rejectOnPrivacyLeak &&
|
||||||
|
formik.errors.rejectOnPrivacyLeak,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{(formik.touched.rejectOnPrivacyLeak &&
|
||||||
|
formik.errors.rejectOnPrivacyLeak) ||
|
||||||
|
t("settings.fields.rejectOnPrivacyLeak.helperText")}
|
||||||
|
</FormHelperText>
|
||||||
|
</FormGroup>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
<LoadingButton
|
<LoadingButton
|
||||||
loading={formik.isSubmitting}
|
loading={formik.isSubmitting}
|
||||||
|
@ -53,6 +53,7 @@ export interface ServerUser {
|
|||||||
aliasImageProxyFormat: ImageProxyFormatType
|
aliasImageProxyFormat: ImageProxyFormatType
|
||||||
aliasProxyUserAgent: ProxyUserAgentType
|
aliasProxyUserAgent: ProxyUserAgentType
|
||||||
aliasExpandUrlShorteners: boolean
|
aliasExpandUrlShorteners: boolean
|
||||||
|
aliasRejectOnPrivacyLeak: boolean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,6 +103,7 @@ export interface Alias {
|
|||||||
prefImageProxyFormat: ImageProxyFormatType | null
|
prefImageProxyFormat: ImageProxyFormatType | null
|
||||||
prefProxyUserAgent: ProxyUserAgentType | null
|
prefProxyUserAgent: ProxyUserAgentType | null
|
||||||
prefExpandUrlShorteners: boolean | null
|
prefExpandUrlShorteners: boolean | null
|
||||||
|
prefRejectOnPrivacyLeak: boolean | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ReservedAlias {
|
export interface ReservedAlias {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user