Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | 15x 22x 22x 22x 22x 2x 22x 1x 21x 21x | import React from "react";
import { useMutation } from "@tanstack/react-query";
import { useTranslation } from "react-i18next";
import { ErrorMessage } from "~app/components/error-message";
import { useTrpcMutationOptions } from "~app/hooks/use-trpc-mutation-options";
import { useTRPC } from "~app/utils/trpc";
import { Button } from "~components/button";
import { ButtonLink } from "~components/link";
import { Text } from "~components/text";
import { View } from "~components/view";
import { options as authVoidUserOptions } from "~mutations/auth/void-user";
type Props = {
token: string;
};
export const VoidUser: React.FC<Props> = ({ token }) => {
const { t } = useTranslation("void-user");
const trpc = useTRPC();
const voidMutation = useMutation(
trpc.auth.voidUser.mutationOptions(
useTrpcMutationOptions(authVoidUserOptions),
),
);
const voidUser = React.useCallback(
() => voidMutation.mutate({ token }),
[voidMutation, token],
);
if (voidMutation.status === "success") {
return (
<>
<Text variant="h3">{voidMutation.data.email}</Text>
<Text variant="h4" className="text-success">
{t("success.message")}
</Text>
<ButtonLink color="primary" to="/login">
{t("success.toLogin")}
</ButtonLink>
</>
);
}
const { isPending } = voidMutation;
return (
<>
<Text variant="h3">{t("confirmation.question")}</Text>
<View className="flex-row gap-2">
<Button
className="flex-1"
onPress={voidUser}
isDisabled={isPending}
isLoading={isPending}
color="danger"
type="submit"
>
{t("confirmation.yes")}
</Button>
<ButtonLink
className="flex-1"
to="/login"
color="primary"
isDisabled={isPending}
>
{t("confirmation.no")}
</ButtonLink>
</View>
{voidMutation.status === "error" ? (
<ErrorMessage message={voidMutation.error.message} />
) : null}
</>
);
};
|