feat: add assessment, privacy and support flows
This commit is contained in:
1 parent
ee3738ee73
commit
e4f24fa202
339 files changed
+56454
-1126
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import type { QueryClient, QueryKey, QueryState } from "@tanstack/react-query";
|
||||
import { getGetCurrentSessionQueryKey } from "../../../shared/api/endpoints/identity/identity";
|
||||
import type { Session } from "../../../shared/api/schemas";
|
||||
|
||||
type SessionSnapshot = Pick<QueryState<Session, Error>, "data" | "status">;
|
||||
|
||||
export function assessmentSessionMatches(
|
||||
snapshot: SessionSnapshot | undefined,
|
||||
actor: Session | undefined,
|
||||
): boolean {
|
||||
return Boolean(
|
||||
snapshot?.status === "success" &&
|
||||
actor &&
|
||||
snapshot.data?.account.id === actor.account.id &&
|
||||
snapshot.data.csrf_token === actor.csrf_token &&
|
||||
actor.account.scenario === "candidate",
|
||||
);
|
||||
}
|
||||
|
||||
export function isCurrentAssessmentSession(
|
||||
queryClient: QueryClient,
|
||||
actor: Session | undefined,
|
||||
): boolean {
|
||||
return assessmentSessionMatches(
|
||||
queryClient.getQueryState<Session>(getGetCurrentSessionQueryKey()),
|
||||
actor,
|
||||
);
|
||||
}
|
||||
|
||||
export function assertCurrentAssessmentSession(
|
||||
queryClient: QueryClient,
|
||||
actor: Session | undefined,
|
||||
): asserts actor is Session {
|
||||
if (!isCurrentAssessmentSession(queryClient, actor)) {
|
||||
throw new Error("The candidate session changed during the assessment request.");
|
||||
}
|
||||
}
|
||||
|
||||
export const assessmentQueryPrefix = ["candidate-assessment"] as const;
|
||||
|
||||
export const assessmentQueryKeys = {
|
||||
availability: (actor: Session) =>
|
||||
[...assessmentQueryPrefix, actor.account.id, actor.csrf_token, "availability"] as const,
|
||||
questionnaire: (actor: Session) =>
|
||||
[...assessmentQueryPrefix, actor.account.id, actor.csrf_token, "questionnaire"] as const,
|
||||
attempt: (actor: Session, attemptId: string) =>
|
||||
[...assessmentQueryPrefix, actor.account.id, actor.csrf_token, "attempt", attemptId] as const,
|
||||
result: (actor: Session, attemptId: string) =>
|
||||
[...assessmentQueryPrefix, actor.account.id, actor.csrf_token, "result", attemptId] as const,
|
||||
};
|
||||
|
||||
export function removeAssessmentQueries(queryClient: QueryClient): void {
|
||||
queryClient.removeQueries({ queryKey: assessmentQueryPrefix });
|
||||
}
|
||||
|
||||
export function removeAssessmentQueriesForSessionChange(
|
||||
queryClient: QueryClient,
|
||||
previousKey?: QueryKey,
|
||||
): void {
|
||||
if (previousKey) {
|
||||
queryClient.removeQueries({ queryKey: previousKey });
|
||||
return;
|
||||
}
|
||||
removeAssessmentQueries(queryClient);
|
||||
}
|
||||
Reference in new issue
Block a user