feat(frontend): simplify the candidate cabinet header
This commit is contained in:
1 parent
90ff71735a
commit
89932b8714
28 files changed
+1154
-179
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { getGetCurrentSessionQueryKey } from "../../../shared/api/endpoints/identity/identity";
|
||||
import type { Session } from "../../../shared/api/schemas";
|
||||
import { paths } from "../../../shared/config";
|
||||
import { requestSignOut } from "./request-sign-out";
|
||||
|
||||
/**
|
||||
* Sign-out command for a cabinet shell. On success the page is replaced by a
|
||||
* full load of the sign-in screen: that drops every in-memory copy of the
|
||||
* account's data (the query cache, form drafts), which a client-side
|
||||
* navigation would keep until the cache is cleared piece by piece. The CSRF
|
||||
* token is read from the cached session when the command runs, so the shell
|
||||
* does not subscribe to the session query.
|
||||
*/
|
||||
export function useSignOut() {
|
||||
const queryClient = useQueryClient();
|
||||
const mutation = useMutation({
|
||||
mutationFn: () =>
|
||||
requestSignOut(queryClient.getQueryData<Session>(getGetCurrentSessionQueryKey())),
|
||||
onSuccess: () => {
|
||||
window.location.assign(paths.login);
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
signOut: () => mutation.mutate(),
|
||||
isPending: mutation.isPending || mutation.isSuccess,
|
||||
failed: mutation.isError,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user