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 | import { useMutation } from "@tanstack/react-query";
import Alert from "components/Alert";
import Button from "components/Button";
import HtmlMeta from "components/HtmlMeta";
import PageTitle from "components/PageTitle";
import { RpcError } from "grpc-web";
import { useTranslation } from "i18n";
import { AUTH, GLOBAL } from "i18n/namespaces";
import { useRouter } from "next/router";
import { service } from "service";
import stringOrFirstString from "utils/stringOrFirstString";
import { UnsubscribeRes } from "../../proto/auth_pb";
interface UnsubscribeParams {
payload?: string;
sig?: string;
}
export default function QuickLink() {
const { t } = useTranslation([AUTH, GLOBAL]);
const router = useRouter();
const payload = stringOrFirstString(router.query.payload);
const sig = stringOrFirstString(router.query.sig);
const {
data,
error,
isPending,
isSuccess,
mutate: unsubscribe,
} = useMutation<UnsubscribeRes.AsObject, RpcError, UnsubscribeParams>({
mutationFn: async ({ payload, sig }) => {
Iif (payload === undefined || sig === undefined) {
throw Error(t("auth:quick_links.missing_payload_or_sig"));
}
return await service.auth.unsubscribe(payload, sig);
},
});
return (
<>
<HtmlMeta title={t("auth:quick_links.title")} />
<PageTitle>{t("auth:quick_links.title")}</PageTitle>
{error && (
<Alert severity="error">
{t("auth:quick_links.error_message", {
message: error.message,
})}
</Alert>
)}
{isSuccess && <Alert severity="success">{data!.response}</Alert>}
<Button onClick={() => unsubscribe({ payload, sig })} loading={isPending}>
{t("auth:quick_links.button_text")}
</Button>
</>
);
}
|