mirror of
https://github.com/Myzel394/kleckrelay-website.git
synced 2025-06-19 07:55:25 +02:00
improvements
This commit is contained in:
parent
1998b430a0
commit
12ac8f9a0b
@ -1,13 +1,16 @@
|
|||||||
import {ReactElement} from "react"
|
import {ReactElement, useState} from "react"
|
||||||
import {useParams} from "react-router-dom"
|
import {useParams} from "react-router-dom"
|
||||||
import {AxiosError} from "axios"
|
import {AxiosError} from "axios"
|
||||||
|
|
||||||
import {useQuery} from "@tanstack/react-query"
|
import {useMutation, useQuery} from "@tanstack/react-query"
|
||||||
import {Grid, Typography} from "@mui/material"
|
import {Grid, Switch, Typography} from "@mui/material"
|
||||||
|
|
||||||
import {getAlias} from "~/apis"
|
import {UpdateAliasData, getAlias, updateAlias} from "~/apis"
|
||||||
import {Alias} from "~/server-types"
|
import {Alias} from "~/server-types"
|
||||||
|
import {ErrorSnack, SuccessSnack} from "~/components"
|
||||||
|
import {parseFastAPIError} from "~/utils"
|
||||||
import AliasPreferencesForm from "~/route-widgets/AliasDetailRoute/AliasPreferencesForm"
|
import AliasPreferencesForm from "~/route-widgets/AliasDetailRoute/AliasPreferencesForm"
|
||||||
|
import AliasTypeIndicator from "~/components/AliasTypeIndicator"
|
||||||
import QueryResult from "~/components/QueryResult"
|
import QueryResult from "~/components/QueryResult"
|
||||||
import SimplePage from "~/components/SimplePage"
|
import SimplePage from "~/components/SimplePage"
|
||||||
|
|
||||||
@ -15,49 +18,106 @@ export default function AliasDetailRoute(): ReactElement {
|
|||||||
const params = useParams()
|
const params = useParams()
|
||||||
const address = atob(params.addressInBase64 as string)
|
const address = atob(params.addressInBase64 as string)
|
||||||
|
|
||||||
|
const [successMessage, setSuccessMessage] = useState<string>("")
|
||||||
|
const [errorMessage, setErrorMessage] = useState<string>("")
|
||||||
|
|
||||||
|
const [isActive, setIsActive] = useState<boolean>(true)
|
||||||
const query = useQuery<Alias, AxiosError>(
|
const query = useQuery<Alias, AxiosError>(
|
||||||
["get_alias", params.addressInBase64],
|
["get_alias", params.addressInBase64],
|
||||||
() => getAlias(address),
|
() => getAlias(address),
|
||||||
|
{
|
||||||
|
onSuccess: alias => setIsActive(alias.isActive),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
const {mutateAsync} = useMutation<Alias, AxiosError, UpdateAliasData>(
|
||||||
|
values => updateAlias(query.data!.id, values),
|
||||||
|
{
|
||||||
|
onSuccess: () => query.refetch(),
|
||||||
|
onError: error => {
|
||||||
|
setErrorMessage(parseFastAPIError(error).detail as string)
|
||||||
|
},
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SimplePage title="Alias Details">
|
<>
|
||||||
<QueryResult<Alias> query={query}>
|
<SimplePage title="Alias Details">
|
||||||
{alias => (
|
<QueryResult<Alias> query={query}>
|
||||||
<Grid container spacing={4}>
|
{alias => (
|
||||||
<Grid item>
|
<Grid container spacing={4}>
|
||||||
<Typography variant="subtitle1">
|
<Grid item>
|
||||||
{address}
|
<Grid
|
||||||
</Typography>
|
container
|
||||||
</Grid>
|
spacing={1}
|
||||||
<Grid item>
|
direction="row"
|
||||||
<Grid container spacing={4}>
|
alignItems="center"
|
||||||
<Grid item>
|
>
|
||||||
<Typography variant="h6">
|
<Grid item>
|
||||||
Settings
|
<AliasTypeIndicator type={alias.type} />
|
||||||
</Typography>
|
</Grid>
|
||||||
|
<Grid item>
|
||||||
|
<Typography variant="subtitle1">
|
||||||
|
{address}
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid item>
|
||||||
|
<Switch
|
||||||
|
checked={isActive}
|
||||||
|
onChange={async () => {
|
||||||
|
setIsActive(!isActive)
|
||||||
|
|
||||||
|
try {
|
||||||
|
await mutateAsync({
|
||||||
|
isActive,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (isActive) {
|
||||||
|
setSuccessMessage(
|
||||||
|
"Alias activated successfully!",
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
setSuccessMessage(
|
||||||
|
"Alias deactivated successfully!",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item>
|
</Grid>
|
||||||
<Typography variant="body1">
|
<Grid item>
|
||||||
These settings apply to this alias only.
|
<Grid container spacing={4}>
|
||||||
You can either set a value manually or
|
<Grid item>
|
||||||
refer to your defaults settings. Note
|
<Typography variant="h6">
|
||||||
that this does change in behavior. When
|
Settings
|
||||||
you set a value to refer to your default
|
</Typography>
|
||||||
setting, the alias will always use the
|
</Grid>
|
||||||
latest value. So when you change your
|
<Grid item>
|
||||||
default setting, the alias will
|
<Typography variant="body1">
|
||||||
automatically use the new value.
|
These settings apply to this alias
|
||||||
</Typography>
|
only. You can either set a value
|
||||||
</Grid>
|
manually or refer to your defaults
|
||||||
<Grid item>
|
settings. Note that this does change
|
||||||
<AliasPreferencesForm alias={alias} />
|
in behavior. When you set a value to
|
||||||
|
refer to your default setting, the
|
||||||
|
alias will always use the latest
|
||||||
|
value. So when you change your
|
||||||
|
default setting, the alias will
|
||||||
|
automatically use the new value.
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid item>
|
||||||
|
<AliasPreferencesForm alias={alias} />
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
)}
|
||||||
)}
|
</QueryResult>
|
||||||
</QueryResult>
|
</SimplePage>
|
||||||
</SimplePage>
|
<SuccessSnack message={successMessage} />
|
||||||
|
<ErrorSnack message={errorMessage} />
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,7 @@ export interface Alias {
|
|||||||
local: string
|
local: string
|
||||||
isActive: boolean
|
isActive: boolean
|
||||||
encryptedNotes: string
|
encryptedNotes: string
|
||||||
|
type: AliasType
|
||||||
|
|
||||||
prefRemoveTrackers: boolean | null
|
prefRemoveTrackers: boolean | null
|
||||||
prefCreateMailReport: boolean | null
|
prefCreateMailReport: boolean | null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user