mirror of
https://github.com/sakaljurgis/best-choice.git
synced 2026-07-08 21:47:40 +00:00
prices panel
This commit is contained in:
@@ -73,3 +73,9 @@ export const createItemPrice = async (
|
|||||||
|
|
||||||
return response.data;
|
return response.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const deleteItemPrice = async (priceId: string): Promise<void> => {
|
||||||
|
await apiFetch<null>(`/prices/${priceId}`, {
|
||||||
|
method: 'DELETE'
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
import { useEffect } from 'react';
|
|
||||||
import type { Item } from '@shared/models/item';
|
|
||||||
import { ItemPricesPanel } from './item-prices-panel';
|
|
||||||
|
|
||||||
interface ItemPricesModalProps {
|
|
||||||
isOpen: boolean;
|
|
||||||
item: Item | null;
|
|
||||||
projectId: string | undefined;
|
|
||||||
onClose: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ItemPricesModal({
|
|
||||||
isOpen,
|
|
||||||
item,
|
|
||||||
projectId,
|
|
||||||
onClose
|
|
||||||
}: ItemPricesModalProps) {
|
|
||||||
useEffect(() => {
|
|
||||||
if (!isOpen) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleKeyDown = (event: KeyboardEvent) => {
|
|
||||||
if (event.key === 'Escape') {
|
|
||||||
onClose();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.addEventListener('keydown', handleKeyDown);
|
|
||||||
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
||||||
}, [isOpen, onClose]);
|
|
||||||
|
|
||||||
if (!isOpen || !item) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const itemTitle = item.manufacturer ? `${item.manufacturer} ${item.model}` : item.model;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className="fixed inset-0 z-50 flex items-center justify-center bg-slate-900/40 px-4 py-10 md:py-16"
|
|
||||||
role="dialog"
|
|
||||||
aria-modal="true"
|
|
||||||
onClick={onClose}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className="relative flex w-full max-w-4xl flex-col overflow-hidden rounded-2xl bg-white shadow-2xl max-h-[calc(100vh-5rem)] md:max-h-[calc(100vh-8rem)]"
|
|
||||||
onClick={(event) => event.stopPropagation()}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={onClose}
|
|
||||||
className="absolute right-4 top-4 rounded-full bg-slate-100 px-3 py-1 text-xs font-semibold uppercase tracking-wide text-slate-500 transition hover:bg-slate-200"
|
|
||||||
>
|
|
||||||
Close
|
|
||||||
</button>
|
|
||||||
<div className="flex-1 overflow-y-auto px-6 py-6 md:px-8 md:py-8">
|
|
||||||
<header className="mb-5 flex flex-col gap-1">
|
|
||||||
<h2 className="text-xl font-semibold text-slate-900">Edit Item Prices</h2>
|
|
||||||
<p className="text-sm text-slate-500">{itemTitle}</p>
|
|
||||||
</header>
|
|
||||||
<ItemPricesPanel itemId={item.id} projectId={projectId} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
import { FormEvent, useMemo, useState } from 'react';
|
import { FormEvent, useMemo, useState } from 'react';
|
||||||
import { useCreateItemPriceMutation, useItemPricesQuery } from '../../query/item-prices';
|
import { Trash2 } from 'lucide-react';
|
||||||
|
import {
|
||||||
|
useCreateItemPriceMutation,
|
||||||
|
useDeleteItemPriceMutation,
|
||||||
|
useItemPricesQuery
|
||||||
|
} from '../../query/item-prices';
|
||||||
import type { PriceCondition } from '../../api/item-prices';
|
import type { PriceCondition } from '../../api/item-prices';
|
||||||
|
import { formatRelativeTime } from '../../utils/relative-time';
|
||||||
|
|
||||||
const priceConditionOptions: PriceCondition[] = ['new', 'used'];
|
const priceConditionOptions: PriceCondition[] = ['new', 'used'];
|
||||||
|
|
||||||
@@ -12,23 +18,39 @@ interface ItemPricesPanelProps {
|
|||||||
export function ItemPricesPanel({ itemId, projectId }: ItemPricesPanelProps) {
|
export function ItemPricesPanel({ itemId, projectId }: ItemPricesPanelProps) {
|
||||||
const [condition, setCondition] = useState<PriceCondition>('new');
|
const [condition, setCondition] = useState<PriceCondition>('new');
|
||||||
const [amount, setAmount] = useState('');
|
const [amount, setAmount] = useState('');
|
||||||
const [currency, setCurrency] = useState('USD');
|
const [currency, setCurrency] = useState('EUR');
|
||||||
const [sourceUrl, setSourceUrl] = useState('');
|
const [sourceUrl, setSourceUrl] = useState('');
|
||||||
const [note, setNote] = useState('');
|
const [note, setNote] = useState('');
|
||||||
const [formError, setFormError] = useState<string | null>(null);
|
const [formError, setFormError] = useState<string | null>(null);
|
||||||
|
const [actionError, setActionError] = useState<string | null>(null);
|
||||||
|
const [pendingDeletionId, setPendingDeletionId] = useState<string | null>(null);
|
||||||
|
|
||||||
const pricesQuery = useItemPricesQuery(itemId, true);
|
const pricesQuery = useItemPricesQuery(itemId, true);
|
||||||
const createPriceMutation = useCreateItemPriceMutation(itemId, projectId);
|
const createPriceMutation = useCreateItemPriceMutation(itemId, projectId);
|
||||||
|
const deletePriceMutation = useDeleteItemPriceMutation(itemId, projectId);
|
||||||
|
|
||||||
const prices = pricesQuery.data?.data ?? [];
|
const prices = pricesQuery.data?.data ?? [];
|
||||||
const creationError = useMemo(
|
const errorMessage = useMemo(
|
||||||
() => formError ?? (createPriceMutation.isError ? createPriceMutation.error.message : null),
|
() =>
|
||||||
[formError, createPriceMutation.isError, createPriceMutation.error]
|
formError ??
|
||||||
|
actionError ??
|
||||||
|
(createPriceMutation.isError ? createPriceMutation.error.message : null) ??
|
||||||
|
(deletePriceMutation.isError ? deletePriceMutation.error.message : null),
|
||||||
|
[
|
||||||
|
formError,
|
||||||
|
actionError,
|
||||||
|
createPriceMutation.isError,
|
||||||
|
createPriceMutation.error,
|
||||||
|
deletePriceMutation.isError,
|
||||||
|
deletePriceMutation.error
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {
|
const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setFormError(null);
|
setFormError(null);
|
||||||
|
setActionError(null);
|
||||||
|
createPriceMutation.reset();
|
||||||
|
|
||||||
const parsedAmount = Number(amount);
|
const parsedAmount = Number(amount);
|
||||||
|
|
||||||
@@ -50,7 +72,21 @@ export function ItemPricesPanel({ itemId, projectId }: ItemPricesPanelProps) {
|
|||||||
setSourceUrl('');
|
setSourceUrl('');
|
||||||
setNote('');
|
setNote('');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setFormError((error as Error).message);
|
setActionError((error as Error).message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeletePrice = async (priceId: string) => {
|
||||||
|
setActionError(null);
|
||||||
|
deletePriceMutation.reset();
|
||||||
|
setPendingDeletionId(priceId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await deletePriceMutation.mutateAsync(priceId);
|
||||||
|
} catch (error) {
|
||||||
|
setActionError((error as Error).message);
|
||||||
|
} finally {
|
||||||
|
setPendingDeletionId(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -78,21 +114,100 @@ export function ItemPricesPanel({ itemId, projectId }: ItemPricesPanelProps) {
|
|||||||
</p>
|
</p>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
<div className="mt-4 grid gap-4 md:grid-cols-2">
|
<form onSubmit={handleSubmit} className="mt-4">
|
||||||
<form
|
<div className="overflow-x-auto rounded-lg border border-slate-200">
|
||||||
className="flex flex-col gap-3 rounded-lg border border-slate-200 bg-slate-50 p-4"
|
<table className="min-w-full divide-y divide-slate-200 text-sm">
|
||||||
onSubmit={handleSubmit}
|
<thead className="bg-slate-50">
|
||||||
|
<tr>
|
||||||
|
<th scope="col" className="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">
|
||||||
|
Condition
|
||||||
|
</th>
|
||||||
|
<th scope="col" className="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">
|
||||||
|
Amount
|
||||||
|
</th>
|
||||||
|
<th scope="col" className="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">
|
||||||
|
Currency
|
||||||
|
</th>
|
||||||
|
<th scope="col" className="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">
|
||||||
|
Source
|
||||||
|
</th>
|
||||||
|
<th scope="col" className="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">
|
||||||
|
Notes
|
||||||
|
</th>
|
||||||
|
<th scope="col" className="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">
|
||||||
|
Updated
|
||||||
|
</th>
|
||||||
|
<th scope="col" className="px-4 py-3 text-right text-xs font-semibold uppercase tracking-wide text-slate-500">
|
||||||
|
Actions
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="divide-y divide-slate-100 bg-white">
|
||||||
|
{pricesQuery.isLoading ? (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={7} className="px-4 py-6 text-center text-xs text-slate-500">
|
||||||
|
Loading prices…
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
) : prices.length ? (
|
||||||
|
prices.map((price) => {
|
||||||
|
const lastUpdated = price.updatedAt ?? price.createdAt;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<tr key={price.id}>
|
||||||
|
<td className="px-4 py-3 capitalize text-slate-800">{price.condition}</td>
|
||||||
|
<td className="px-4 py-3 text-slate-800">{price.amount.toFixed(2)}</td>
|
||||||
|
<td className="px-4 py-3 text-slate-800">{price.currency}</td>
|
||||||
|
<td className="px-4 py-3 text-slate-800">
|
||||||
|
{price.sourceUrl ? (
|
||||||
|
<a
|
||||||
|
href={price.sourceUrl}
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
className="text-blue-600 hover:text-blue-700"
|
||||||
>
|
>
|
||||||
<div className="grid grid-cols-2 gap-3">
|
View source
|
||||||
<div className="flex flex-col gap-1.5">
|
</a>
|
||||||
<label className="text-xs font-medium text-slate-600" htmlFor={`price-condition-${itemId}`}>
|
) : (
|
||||||
|
<span className="text-slate-400">—</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-3 text-slate-800">
|
||||||
|
{price.note ? price.note : <span className="text-slate-400">—</span>}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-3 text-slate-600">
|
||||||
|
{lastUpdated ? formatRelativeTime(lastUpdated) : <span className="text-slate-400">—</span>}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-3 text-right">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => handleDeletePrice(price.id)}
|
||||||
|
className="inline-flex items-center gap-1 rounded-md border border-red-200 bg-red-50 px-2 py-1.5 text-xs font-semibold text-red-600 transition hover:bg-red-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-red-500 focus-visible:ring-offset-2 focus-visible:ring-offset-white disabled:cursor-not-allowed disabled:opacity-60"
|
||||||
|
disabled={deletePriceMutation.isPending && pendingDeletionId === price.id}
|
||||||
|
>
|
||||||
|
<Trash2 aria-hidden className="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
) : (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={7} className="px-4 py-6 text-center text-xs text-slate-500">
|
||||||
|
No prices recorded yet.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
<tr className="bg-slate-50">
|
||||||
|
<td className="px-4 py-3">
|
||||||
|
<label className="sr-only" htmlFor={`price-condition-${itemId}`}>
|
||||||
Condition
|
Condition
|
||||||
</label>
|
</label>
|
||||||
<select
|
<select
|
||||||
id={`price-condition-${itemId}`}
|
id={`price-condition-${itemId}`}
|
||||||
value={condition}
|
value={condition}
|
||||||
onChange={(event) => setCondition(event.target.value as PriceCondition)}
|
onChange={(event) => setCondition(event.target.value as PriceCondition)}
|
||||||
className="rounded-md border border-slate-300 px-2 py-2 text-sm shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200"
|
className="w-full rounded-md border border-slate-300 px-2 py-2 text-sm shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200"
|
||||||
>
|
>
|
||||||
{priceConditionOptions.map((option) => (
|
{priceConditionOptions.map((option) => (
|
||||||
<option key={option} value={option}>
|
<option key={option} value={option}>
|
||||||
@@ -100,9 +215,9 @@ export function ItemPricesPanel({ itemId, projectId }: ItemPricesPanelProps) {
|
|||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</td>
|
||||||
<div className="flex flex-col gap-1.5">
|
<td className="px-4 py-3">
|
||||||
<label className="text-xs font-medium text-slate-600" htmlFor={`price-amount-${itemId}`}>
|
<label className="sr-only" htmlFor={`price-amount-${itemId}`}>
|
||||||
Amount
|
Amount
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
@@ -112,15 +227,13 @@ export function ItemPricesPanel({ itemId, projectId }: ItemPricesPanelProps) {
|
|||||||
step="0.01"
|
step="0.01"
|
||||||
value={amount}
|
value={amount}
|
||||||
onChange={(event) => setAmount(event.target.value)}
|
onChange={(event) => setAmount(event.target.value)}
|
||||||
className="rounded-md border border-slate-300 px-2 py-2 text-sm shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200"
|
className="w-full rounded-md border border-slate-300 px-2 py-2 text-sm shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200"
|
||||||
placeholder="129.99"
|
placeholder="129.99"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</td>
|
||||||
</div>
|
<td className="px-4 py-3">
|
||||||
|
<label className="sr-only" htmlFor={`price-currency-${itemId}`}>
|
||||||
<div className="flex flex-col gap-1.5">
|
|
||||||
<label className="text-xs font-medium text-slate-600" htmlFor={`price-currency-${itemId}`}>
|
|
||||||
Currency
|
Currency
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
@@ -129,14 +242,13 @@ export function ItemPricesPanel({ itemId, projectId }: ItemPricesPanelProps) {
|
|||||||
value={currency}
|
value={currency}
|
||||||
onChange={(event) => setCurrency(event.target.value.toUpperCase())}
|
onChange={(event) => setCurrency(event.target.value.toUpperCase())}
|
||||||
maxLength={3}
|
maxLength={3}
|
||||||
className="uppercase rounded-md border border-slate-300 px-2 py-2 text-sm shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200"
|
className="w-full rounded-md border border-slate-300 px-2 py-2 text-sm uppercase shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200"
|
||||||
placeholder="USD"
|
placeholder="EUR"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</td>
|
||||||
|
<td className="px-4 py-3">
|
||||||
<div className="flex flex-col gap-1.5">
|
<label className="sr-only" htmlFor={`price-source-url-${itemId}`}>
|
||||||
<label className="text-xs font-medium text-slate-600" htmlFor={`price-source-url-${itemId}`}>
|
|
||||||
Source URL
|
Source URL
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
@@ -144,88 +256,41 @@ export function ItemPricesPanel({ itemId, projectId }: ItemPricesPanelProps) {
|
|||||||
type="url"
|
type="url"
|
||||||
value={sourceUrl}
|
value={sourceUrl}
|
||||||
onChange={(event) => setSourceUrl(event.target.value)}
|
onChange={(event) => setSourceUrl(event.target.value)}
|
||||||
className="rounded-md border border-slate-300 px-2 py-2 text-sm shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200"
|
className="w-full rounded-md border border-slate-300 px-2 py-2 text-sm shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200"
|
||||||
placeholder="https://shop.example.com/deal"
|
placeholder="https://shop.example.com/deal"
|
||||||
/>
|
/>
|
||||||
</div>
|
</td>
|
||||||
|
<td className="px-4 py-3">
|
||||||
<div className="flex flex-col gap-1.5">
|
<label className="sr-only" htmlFor={`price-note-${itemId}`}>
|
||||||
<label className="text-xs font-medium text-slate-600" htmlFor={`price-note-${itemId}`}>
|
|
||||||
Notes
|
Notes
|
||||||
</label>
|
</label>
|
||||||
<textarea
|
<textarea
|
||||||
id={`price-note-${itemId}`}
|
id={`price-note-${itemId}`}
|
||||||
value={note}
|
value={note}
|
||||||
onChange={(event) => setNote(event.target.value)}
|
onChange={(event) => setNote(event.target.value)}
|
||||||
rows={2}
|
rows={1}
|
||||||
className="rounded-md border border-slate-300 px-2 py-2 text-sm shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200"
|
className="w-full rounded-md border border-slate-300 px-2 py-2 text-sm shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200"
|
||||||
placeholder="Includes extra grip kit"
|
placeholder="Includes extra grip kit"
|
||||||
/>
|
/>
|
||||||
</div>
|
</td>
|
||||||
|
<td className="px-4 py-3 text-slate-400">—</td>
|
||||||
{creationError ? (
|
<td className="px-4 py-3 text-right">
|
||||||
<p className="rounded-md bg-red-50 px-3 py-2 text-xs text-red-600">{creationError}</p>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
<div className="flex items-center justify-end gap-3 pt-1">
|
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
className="rounded-md bg-blue-600 px-4 py-2 text-sm font-semibold text-white transition hover:bg-blue-700 disabled:cursor-not-allowed disabled:bg-blue-400"
|
className="rounded-md bg-blue-600 px-3 py-2 text-sm font-semibold text-white transition hover:bg-blue-700 disabled:cursor-not-allowed disabled:bg-blue-400"
|
||||||
disabled={createPriceMutation.isPending}
|
disabled={createPriceMutation.isPending}
|
||||||
>
|
>
|
||||||
{createPriceMutation.isPending ? 'Adding…' : 'Add Price'}
|
{createPriceMutation.isPending ? 'Adding…' : 'Add Price'}
|
||||||
</button>
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
{errorMessage ? (
|
||||||
|
<p className="mt-3 rounded-md bg-red-50 px-3 py-2 text-xs text-red-600">{errorMessage}</p>
|
||||||
|
) : null}
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div className="space-y-3">
|
|
||||||
{prices.map((price) => (
|
|
||||||
<article
|
|
||||||
key={price.id}
|
|
||||||
className="rounded-lg border border-slate-200 bg-white px-4 py-3 text-sm shadow-sm"
|
|
||||||
>
|
|
||||||
<header className="flex items-center justify-between">
|
|
||||||
<span className="font-semibold text-slate-900">
|
|
||||||
{price.condition} • {price.amount.toFixed(2)} {price.currency}
|
|
||||||
</span>
|
|
||||||
</header>
|
|
||||||
<dl className="mt-2 space-y-1 text-xs text-slate-600">
|
|
||||||
{price.sourceUrl ? (
|
|
||||||
<div>
|
|
||||||
<dt className="font-medium text-slate-500">Source URL</dt>
|
|
||||||
<dd>
|
|
||||||
<a
|
|
||||||
href={price.sourceUrl}
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
className="text-blue-600 hover:text-blue-700"
|
|
||||||
>
|
|
||||||
View source
|
|
||||||
</a>
|
|
||||||
</dd>
|
|
||||||
</div>
|
|
||||||
) : null}
|
|
||||||
{price.note ? (
|
|
||||||
<div>
|
|
||||||
<dt className="font-medium text-slate-500">Notes</dt>
|
|
||||||
<dd>{price.note}</dd>
|
|
||||||
</div>
|
|
||||||
) : null}
|
|
||||||
<div>
|
|
||||||
<dt className="font-medium text-slate-500">Created</dt>
|
|
||||||
<dd>{new Date(price.createdAt).toLocaleString()}</dd>
|
|
||||||
</div>
|
|
||||||
{price.updatedAt !== price.createdAt ? (
|
|
||||||
<div>
|
|
||||||
<dt className="font-medium text-slate-500">Updated</dt>
|
|
||||||
<dd>{new Date(price.updatedAt).toLocaleString()}</dd>
|
|
||||||
</div>
|
|
||||||
) : null}
|
|
||||||
</dl>
|
|
||||||
</article>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
import {
|
import {
|
||||||
createItemPrice,
|
createItemPrice,
|
||||||
|
deleteItemPrice,
|
||||||
fetchItemPrices,
|
fetchItemPrices,
|
||||||
type CreateItemPricePayload,
|
type CreateItemPricePayload,
|
||||||
type ItemPricesResponse
|
type ItemPricesResponse
|
||||||
@@ -50,3 +51,23 @@ export const useCreateItemPriceMutation = (
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useDeleteItemPriceMutation = (
|
||||||
|
itemId: string | undefined,
|
||||||
|
projectId: string | undefined
|
||||||
|
) => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (priceId: string) => deleteItemPrice(priceId),
|
||||||
|
onSuccess: () => {
|
||||||
|
if (itemId) {
|
||||||
|
queryClient.invalidateQueries({ queryKey: itemPricesKeys.list(itemId) });
|
||||||
|
}
|
||||||
|
if (projectId) {
|
||||||
|
queryClient.invalidateQueries({ queryKey: projectsKeys.items(projectId) });
|
||||||
|
queryClient.invalidateQueries({ queryKey: projectsKeys.detail(projectId) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user