mirror of
https://github.com/andwati/cymelle.git
synced 2026-11-20 15:08:47 +00:00
completed frontend v1
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
export function formatCurrency(amount: number, currency = "KES") {
|
||||
return new Intl.NumberFormat("en-KE", {
|
||||
style: "currency",
|
||||
currency,
|
||||
maximumFractionDigits: 2,
|
||||
}).format(amount);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
export function formatDate(value: string | null | undefined) {
|
||||
if (!value) {
|
||||
return "—";
|
||||
}
|
||||
|
||||
return new Intl.DateTimeFormat("en-KE", {
|
||||
dateStyle: "medium",
|
||||
timeStyle: "short",
|
||||
}).format(new Date(value));
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import {calculateFare} from "#/api/fare";
|
||||
import {useMutation} from "@tanstack/react-query";
|
||||
|
||||
type FareCalculationInput = {
|
||||
distanceKm: number;
|
||||
surgeMultiplier?: number;
|
||||
};
|
||||
|
||||
export function useFareCalculation() {
|
||||
return useMutation({
|
||||
mutationFn: ({distanceKm, surgeMultiplier}: FareCalculationInput) =>
|
||||
calculateFare(distanceKm, surgeMultiplier),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import {getInventory, getLowStockInventory} from "#/api/inventory";
|
||||
import {useQuery} from "@tanstack/react-query";
|
||||
|
||||
export const inventoryQueryKeys = {
|
||||
all: ["inventory"] as const,
|
||||
list: () => [...inventoryQueryKeys.all, "list"] as const,
|
||||
lowStock: (threshold?: number) =>
|
||||
[...inventoryQueryKeys.all, "low-stock", threshold ?? "default"] as const,
|
||||
};
|
||||
|
||||
export function useInventory() {
|
||||
return useQuery({
|
||||
queryKey: inventoryQueryKeys.list(),
|
||||
queryFn: ({signal}) => getInventory(signal),
|
||||
});
|
||||
}
|
||||
|
||||
export function useLowStockInventory(threshold?: number) {
|
||||
return useQuery({
|
||||
queryKey: inventoryQueryKeys.lowStock(threshold),
|
||||
queryFn: ({signal}) => getLowStockInventory(threshold, signal),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import {cancelOrder, getOrders} from "#/api/orders";
|
||||
import {inventoryQueryKeys} from "#/hooks/useInventory";
|
||||
import type {OrderFilters} from "#/types/order";
|
||||
import {useMutation, useQuery, useQueryClient} from "@tanstack/react-query";
|
||||
|
||||
export const orderQueryKeys = {
|
||||
all: ["orders"] as const,
|
||||
list: (filters: OrderFilters, page = 0, size = 20) =>
|
||||
[...orderQueryKeys.all, "list", filters, page, size] as const,
|
||||
};
|
||||
|
||||
export function useOrders(filters: OrderFilters, page = 0, size = 20) {
|
||||
return useQuery({
|
||||
queryKey: orderQueryKeys.list(filters, page, size),
|
||||
queryFn: ({signal}) => getOrders(filters, page, size, signal),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCancelOrder() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: cancelOrder,
|
||||
onSuccess: async () => {
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: orderQueryKeys.all,
|
||||
}),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: inventoryQueryKeys.all,
|
||||
}),
|
||||
]);
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user