fixed back button with source, and customer in customer lsit clickable

This commit is contained in:
2026-03-21 12:16:04 +01:00
parent d7b42f64b1
commit eecc6cd73e
7 changed files with 38 additions and 23 deletions
@@ -1,5 +1,5 @@
import { useEffect } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { useNavigate, useParams, useLocation } from 'react-router-dom';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { useForm } from 'react-hook-form';
import { customerApi } from '../../services/api';
@@ -14,8 +14,10 @@ type CustomerFormData = Omit<Customer, 'id' | 'customerNumber' | 'createdAt' | '
export default function CustomerForm() {
const { id } = useParams();
const navigate = useNavigate();
const location = useLocation();
const queryClient = useQueryClient();
const isEdit = !!id;
const backTo = (location.state as any)?.from as string | undefined;
const { register, handleSubmit, reset, watch, setValue, formState: { errors } } = useForm<CustomerFormData>();
const customerType = watch('type');
@@ -232,7 +234,7 @@ export default function CustomerForm() {
</Card>
<div className="flex justify-end gap-4">
<Button type="button" variant="secondary" onClick={() => navigate(isEdit ? `/customers/${id}` : '/customers')}>
<Button type="button" variant="secondary" onClick={() => navigate(backTo || (isEdit ? `/customers/${id}` : '/customers'))}>
Abbrechen
</Button>
<Button type="submit" disabled={isLoading}>