feat: enhance API response handling and add new components for module management
This commit is contained in:
@@ -5,7 +5,6 @@ import { useCallback, useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
import { Plus } from 'lucide-react';
|
||||
import { useAction } from 'next-safe-action/hooks';
|
||||
|
||||
import { createDepartment } from '@kit/member-management/actions/member-actions';
|
||||
import { Button } from '@kit/ui/button';
|
||||
@@ -20,7 +19,7 @@ import {
|
||||
} from '@kit/ui/dialog';
|
||||
import { Input } from '@kit/ui/input';
|
||||
import { Label } from '@kit/ui/label';
|
||||
import { toast } from '@kit/ui/sonner';
|
||||
import { useActionWithToast } from '@kit/ui/use-action-with-toast';
|
||||
|
||||
interface CreateDepartmentDialogProps {
|
||||
accountId: string;
|
||||
@@ -34,18 +33,14 @@ export function CreateDepartmentDialog({
|
||||
const [name, setName] = useState('');
|
||||
const [description, setDescription] = useState('');
|
||||
|
||||
const { execute, isPending } = useAction(createDepartment, {
|
||||
onSuccess: ({ data }) => {
|
||||
if (data?.success) {
|
||||
toast.success('Abteilung erstellt');
|
||||
setOpen(false);
|
||||
setName('');
|
||||
setDescription('');
|
||||
router.refresh();
|
||||
}
|
||||
},
|
||||
onError: ({ error }) => {
|
||||
toast.error(error.serverError ?? 'Fehler beim Erstellen der Abteilung');
|
||||
const { execute, isPending } = useActionWithToast(createDepartment, {
|
||||
successMessage: 'Abteilung erstellt',
|
||||
errorMessage: 'Fehler beim Erstellen der Abteilung',
|
||||
onSuccess: () => {
|
||||
setOpen(false);
|
||||
setName('');
|
||||
setDescription('');
|
||||
router.refresh();
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user