mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-04 16:02:08 +00:00
- Sites page: Add Site modal with Site Code, Client, address, State/Area, optional Site Phone and Email, points of contact - Duplicate Site Code shows inline under the field and keeps the modal open - Row opens a non-modal detail panel; Street Address links to Google Maps; key-less map preview - Edit switches the panel in place with Site Code read-only; Save needs a valid change, Cancel makes no call - Site Phone is sent independently of the contacts; zip and title are carried through edits - Retire the separate new/edit location pages
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { useMutation, useQueryClient, type UseMutationResult } from "@tanstack/react-query";
|
|
import { toast } from "react-toastify";
|
|
import { locationsApi } from "@/domain/locations/api/locations-api";
|
|
import type { LocationFormValues } from "@/domain/locations/schemas/location-schema";
|
|
import { queryKeys } from "@/infra/query-key/query-key";
|
|
|
|
interface UpdateLocationInput {
|
|
id: string | number;
|
|
values: LocationFormValues;
|
|
}
|
|
|
|
/** Saves a site. The response carries no site, so the list and detail are refetched. */
|
|
export function useUpdateLocation(): UseMutationResult<void, Error, UpdateLocationInput> {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: async ({ id, values }: UpdateLocationInput) => {
|
|
await locationsApi.update(id, values);
|
|
},
|
|
onSuccess: async (_data, variables) => {
|
|
await Promise.all([
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.locations.all }),
|
|
queryClient.invalidateQueries({
|
|
queryKey: queryKeys.locations.detail(String(variables.id)),
|
|
}),
|
|
]);
|
|
toast.success("Site updated");
|
|
},
|
|
onError: (error: Error) => {
|
|
toast.error(error.message || "Failed to update site");
|
|
},
|
|
});
|
|
}
|