@@ -1,12 +1,11 @@
|
||||
import type { EventInfo } from '../types';
|
||||
import type { KycSubmission } from './kyc.types';
|
||||
import { Dialog } from '@radix-ui/react-dialog';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useStore } from 'zustand';
|
||||
import { postEventJoin, postKycQuery } from '@/client';
|
||||
import { getEventListInfiniteQueryKey } from '@/client/@tanstack/react-query.gen';
|
||||
import { postKycQuery } from '@/client';
|
||||
import { useCreateKycSession } from '@/hooks/data/useCreateKycSession';
|
||||
import { useJoinEvent } from '@/hooks/data/useJoinEvent';
|
||||
import { KycFailedDialogView } from './kyc-failed.dialog.view';
|
||||
import { KycMethodSelectionDialogView } from './kyc-method-selection.dialog.view';
|
||||
import { KycPendingDialogView } from './kyc-pending.dialog.view';
|
||||
@@ -22,12 +21,12 @@ export function KycDialogContainer({ event, children }: { event: EventInfo; chil
|
||||
const setStage = useStore(store, s => s.setStage);
|
||||
const setKycId = useStore(store, s => s.setKycId);
|
||||
|
||||
const { mutateAsync } = useCreateKycSession();
|
||||
const queryClient = useQueryClient();
|
||||
const { mutateAsync: createKycSessionAsync } = useCreateKycSession();
|
||||
const { mutateAsync: joinEventAsync } = useJoinEvent();
|
||||
|
||||
const joinEvent = useCallback(async (eventId: string, kycId: string, abortSignal?: AbortSignal) => {
|
||||
try {
|
||||
await postEventJoin({
|
||||
await joinEventAsync({
|
||||
signal: abortSignal,
|
||||
body: { event_id: eventId, kyc_id: kycId },
|
||||
});
|
||||
@@ -37,11 +36,11 @@ export function KycDialogContainer({ event, children }: { event: EventInfo; chil
|
||||
console.error('Error joining event:', e);
|
||||
setStage('failed');
|
||||
}
|
||||
}, [setStage]);
|
||||
}, [joinEventAsync, setStage]);
|
||||
|
||||
const onKycSessionCreate = useCallback(async (submission: KycSubmission) => {
|
||||
try {
|
||||
const { data } = await mutateAsync(submission);
|
||||
const { data } = await createKycSessionAsync(submission);
|
||||
setKycId(data!.kyc_id!);
|
||||
if (data!.status === 'success') {
|
||||
await joinEvent(event.eventId, data!.kyc_id!, undefined);
|
||||
@@ -55,7 +54,7 @@ export function KycDialogContainer({ event, children }: { event: EventInfo; chil
|
||||
console.error(e);
|
||||
setStage('failed');
|
||||
}
|
||||
}, [event.eventId, joinEvent, mutateAsync, setKycId, setStage]);
|
||||
}, [event.eventId, joinEvent, createKycSessionAsync, setKycId, setStage]);
|
||||
|
||||
useEffect(() => {
|
||||
if (stage !== 'pending' || !isDialogOpen) {
|
||||
@@ -107,14 +106,7 @@ export function KycDialogContainer({ event, children }: { event: EventInfo; chil
|
||||
return (
|
||||
<Dialog
|
||||
open={isDialogOpen}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey: getEventListInfiniteQueryKey({ query: {} }),
|
||||
});
|
||||
}
|
||||
setIsDialogOpen(open);
|
||||
}}
|
||||
onOpenChange={setIsDialogOpen}
|
||||
>
|
||||
{children}
|
||||
{stage === 'prompt' && <KycPromptDialogView next={() => setStage('methodSelection')} />}
|
||||
|
||||
Reference in New Issue
Block a user