pos implemented

This commit is contained in:
2026-08-10 18:14:52 +05:30
parent 14e4529613
commit 31d5535b72
14 changed files with 1373 additions and 301 deletions

View File

@@ -48,6 +48,11 @@ import {
getProductStocks,
getProductLocations,
createProductLocations,
getPosRoles,
getPosStaff,
createPosStaff,
updatePosStaff,
deactivatePosStaff,
getMasterCatalog,
getProductCategories,
getProductSubcategories,
@@ -1055,3 +1060,64 @@ export function useFiestaDeleteProductLocation() {
},
});
}
// ── POS staff (supervisors and cashiers) ────────────────────────────────────
//
// Separate from useFiestaUsers: the backend excludes roleid 7 and 8 from
// `getallusers`, so these people are invisible to that hook by design. Do not
// "fix" that by merging the two lists — a till account and a console account
// are different things with different creation paths.
export const posStaffKeys = {
roles: () => ['fiesta', 'posroles'] as const,
staff: (tenantid: number, locationid: number) =>
['fiesta', 'posstaff', tenantid, locationid] as const,
};
/** The till roles the backend offers. Cached hard — this changes with a deploy. */
export function usePosRoles() {
return useQuery({
queryKey: posStaffKeys.roles(),
queryFn: getPosRoles,
staleTime: 30 * 60_000,
});
}
export function usePosStaff(tenantid: number, locationid: number) {
return useQuery({
queryKey: posStaffKeys.staff(tenantid, locationid),
queryFn: () => getPosStaff({ tenantid, locationid }),
enabled: Boolean(tenantid) && Boolean(locationid),
});
}
/** Create a till account. The resolved value carries the one-time password. */
export function useCreatePosStaff() {
const qc = useQueryClient();
return useMutation({
mutationFn: createPosStaff,
onSuccess: (_res, vars) => {
qc.invalidateQueries({ queryKey: posStaffKeys.staff(vars.tenantid, vars.locationid) });
},
});
}
export function useUpdatePosStaff() {
const qc = useQueryClient();
return useMutation({
mutationFn: updatePosStaff,
onSuccess: (_res, vars) => {
qc.invalidateQueries({ queryKey: posStaffKeys.staff(vars.tenantid, vars.locationid) });
},
});
}
export function useDeactivatePosStaff() {
const qc = useQueryClient();
return useMutation({
mutationFn: deactivatePosStaff,
onSuccess: (_res, vars) => {
qc.invalidateQueries({ queryKey: posStaffKeys.staff(vars.tenantid, vars.locationid) });
},
});
}