feat: enhance API response handling and add new components for module management
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useAction } from 'next-safe-action/hooks';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
import { Button } from '@kit/ui/button';
|
||||
@@ -17,7 +16,7 @@ import {
|
||||
FormMessage,
|
||||
} from '@kit/ui/form';
|
||||
import { Input } from '@kit/ui/input';
|
||||
import { toast } from '@kit/ui/sonner';
|
||||
import { useActionWithToast } from '@kit/ui/use-action-with-toast';
|
||||
|
||||
import { CreateMemberClubSchema } from '../schema/verband.schema';
|
||||
import { createClub } from '../server/actions/verband-actions';
|
||||
@@ -62,15 +61,11 @@ export function CreateClubForm({
|
||||
},
|
||||
});
|
||||
|
||||
const { execute, isPending } = useAction(createClub, {
|
||||
onSuccess: ({ data }) => {
|
||||
if (data?.success) {
|
||||
toast.success(isEdit ? 'Verein aktualisiert' : 'Verein erstellt');
|
||||
router.push(`/home/${account}/verband/clubs`);
|
||||
}
|
||||
},
|
||||
onError: ({ error }) => {
|
||||
toast.error(error.serverError ?? 'Fehler beim Speichern');
|
||||
const { execute, isPending } = useActionWithToast(createClub, {
|
||||
successMessage: isEdit ? 'Verein aktualisiert' : 'Verein erstellt',
|
||||
errorMessage: 'Fehler beim Speichern',
|
||||
onSuccess: () => {
|
||||
router.push(`/home/${account}/verband/clubs`);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ import {
|
||||
DialogTitle,
|
||||
} from '@kit/ui/dialog';
|
||||
import { Input } from '@kit/ui/input';
|
||||
import { toast } from '@kit/ui/sonner';
|
||||
import { Textarea } from '@kit/ui/textarea';
|
||||
import { useActionWithToast } from '@kit/ui/use-action-with-toast';
|
||||
|
||||
import {
|
||||
getTransferPreview,
|
||||
@@ -90,7 +90,7 @@ export function CrossOrgMemberSearch({
|
||||
|
||||
const { execute: executePreview } = useAction(getTransferPreview, {
|
||||
onSuccess: ({ data }) => {
|
||||
if (data) setPreview(data);
|
||||
if (data?.data) setPreview(data.data);
|
||||
setPreviewLoading(false);
|
||||
},
|
||||
onError: () => {
|
||||
@@ -98,22 +98,18 @@ export function CrossOrgMemberSearch({
|
||||
},
|
||||
});
|
||||
|
||||
const { execute: executeTransfer, isPending: isTransferring } = useAction(
|
||||
transferMember,
|
||||
{
|
||||
const { execute: executeTransfer, isPending: isTransferring } =
|
||||
useActionWithToast(transferMember, {
|
||||
successMessage: 'Mitglied erfolgreich transferiert',
|
||||
errorMessage: 'Fehler beim Transfer',
|
||||
onSuccess: () => {
|
||||
toast.success('Mitglied erfolgreich transferiert');
|
||||
setTransferTarget(null);
|
||||
setTargetAccountId('');
|
||||
setTransferReason('');
|
||||
setKeepSepa(true);
|
||||
setPreview(null);
|
||||
},
|
||||
onError: ({ error }) => {
|
||||
toast.error(error.serverError ?? 'Fehler beim Transfer');
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
const buildUrl = useCallback(
|
||||
(params: Record<string, string | number | null>) => {
|
||||
|
||||
@@ -135,7 +135,8 @@ export const getTransferPreview = authActionClient
|
||||
const client = getSupabaseServerClient();
|
||||
const api = createVerbandApi(client);
|
||||
|
||||
return api.getTransferPreview(input.memberId);
|
||||
const data = await api.getTransferPreview(input.memberId);
|
||||
return { success: true, data };
|
||||
});
|
||||
|
||||
export const transferMember = authActionClient
|
||||
@@ -169,7 +170,7 @@ export const transferMember = authActionClient
|
||||
);
|
||||
|
||||
revalidatePath(REVALIDATE_PATH, 'page');
|
||||
return { success: true, transferId };
|
||||
return { success: true, data: { transferId } };
|
||||
} catch (err) {
|
||||
const message =
|
||||
err instanceof Error ? err.message : 'Fehler beim Transfer';
|
||||
@@ -202,5 +203,5 @@ export const cloneTemplate = authActionClient
|
||||
);
|
||||
|
||||
revalidatePath(REVALIDATE_PATH, 'page');
|
||||
return { success: true, newTemplateId };
|
||||
return { success: true, data: { newTemplateId } };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user