Migrate all kitchen frontend fetch calls to /kitchen/api/ prefix (B5b)
All archive components were calling fetch('/api/...') directly. Replaced
all occurrences of /api/ URLs (string literals, template literals,
window.open, src attributes) with /kitchen/api/ across 37 source files.
The central axios instance in api.ts was already correct.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ecd63fc65f
commit
9905d0e0dd
51 changed files with 453 additions and 453 deletions
|
|
@ -541,7 +541,7 @@ export default function Review() {
|
|||
const { data: invoice, isLoading, refetch: refetchInvoice } = useQuery<Invoice>({
|
||||
queryKey: ['invoice', id],
|
||||
queryFn: async () => {
|
||||
const res = await fetch(`/api/invoices/${id}`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch invoice')
|
||||
|
|
@ -553,13 +553,13 @@ export default function Review() {
|
|||
|
||||
// Direct URL with token - simpler approach
|
||||
const imageUrl = invoice
|
||||
? `/api/invoices/${id}/file?token=${encodeURIComponent(token || '')}#toolbar=0&navpanes=0&view=FitH`
|
||||
? `/kitchen/api/invoices/${id}/file?token=${encodeURIComponent(token || '')}#toolbar=0&navpanes=0&view=FitH`
|
||||
: null
|
||||
|
||||
const { data: lineItems, refetch: refetchLineItems } = useQuery<LineItem[]>({
|
||||
queryKey: ['invoice-line-items', id],
|
||||
queryFn: async () => {
|
||||
const res = await fetch(`/api/invoices/${id}/line-items`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}/line-items`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch line items')
|
||||
|
|
@ -576,7 +576,7 @@ export default function Review() {
|
|||
}>>({
|
||||
queryKey: ['invoice-stock-history', id],
|
||||
queryFn: async () => {
|
||||
const res = await fetch(`/api/invoices/${id}/stock-history`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}/stock-history`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch stock history')
|
||||
|
|
@ -588,7 +588,7 @@ export default function Review() {
|
|||
const { data: duplicateInfo } = useQuery<DuplicateCompare>({
|
||||
queryKey: ['invoice-duplicates', id],
|
||||
queryFn: async () => {
|
||||
const res = await fetch(`/api/invoices/${id}/duplicates`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}/duplicates`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch duplicates')
|
||||
|
|
@ -600,7 +600,7 @@ export default function Review() {
|
|||
const { data: rawOcrData } = useQuery<{ raw_json: any; raw_text: string }>({
|
||||
queryKey: ['invoice-ocr-data', id],
|
||||
queryFn: async () => {
|
||||
const res = await fetch(`/api/invoices/${id}/ocr-data`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}/ocr-data`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch OCR data')
|
||||
|
|
@ -612,7 +612,7 @@ export default function Review() {
|
|||
const { data: settings } = useQuery<Settings>({
|
||||
queryKey: ['settings'],
|
||||
queryFn: async () => {
|
||||
const res = await fetch('/api/settings/', {
|
||||
const res = await fetch('/kitchen/api/settings/', {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch settings')
|
||||
|
|
@ -637,7 +637,7 @@ export default function Review() {
|
|||
const uniqueItems = Array.from(new Map(items.map(i => [i.description.toLowerCase(), i])).values())
|
||||
if (uniqueItems.length === 0) return
|
||||
|
||||
fetch('/api/ingredients/sources/alias-suggestions', {
|
||||
fetch('/kitchen/api/ingredients/sources/alias-suggestions', {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ supplier_id: parseInt(supplierId), items: uniqueItems }),
|
||||
|
|
@ -885,7 +885,7 @@ export default function Review() {
|
|||
const { data: suppliers } = useQuery<Supplier[]>({
|
||||
queryKey: ['suppliers'],
|
||||
queryFn: async () => {
|
||||
const res = await fetch('/api/suppliers/', {
|
||||
const res = await fetch('/kitchen/api/suppliers/', {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (!res.ok) return []
|
||||
|
|
@ -915,7 +915,7 @@ export default function Review() {
|
|||
}>({
|
||||
queryKey: ['po-match', id],
|
||||
queryFn: async () => {
|
||||
const res = await fetch(`/api/purchase-orders/matching/for-invoice?invoice_id=${id}`, {
|
||||
const res = await fetch(`/kitchen/api/purchase-orders/matching/for-invoice?invoice_id=${id}`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (!res.ok) return { matches: [], linked_po: null }
|
||||
|
|
@ -944,7 +944,7 @@ export default function Review() {
|
|||
|
||||
const pollInterval = setInterval(async () => {
|
||||
try {
|
||||
const checkRes = await fetch(`/api/invoices/${id}`, {
|
||||
const checkRes = await fetch(`/kitchen/api/invoices/${id}`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (checkRes.ok) {
|
||||
|
|
@ -971,7 +971,7 @@ export default function Review() {
|
|||
|
||||
try {
|
||||
// Fetch the PDF
|
||||
const pdfUrl = `/api/invoices/${id}/file?token=${encodeURIComponent(token)}`
|
||||
const pdfUrl = `/kitchen/api/invoices/${id}/file?token=${encodeURIComponent(token)}`
|
||||
const response = await fetch(pdfUrl)
|
||||
const arrayBuffer = await response.arrayBuffer()
|
||||
|
||||
|
|
@ -1041,7 +1041,7 @@ export default function Review() {
|
|||
|
||||
const updateMutation = useMutation({
|
||||
mutationFn: async (data: Partial<Invoice>) => {
|
||||
const res = await fetch(`/api/invoices/${id}`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
|
|
@ -1067,7 +1067,7 @@ export default function Review() {
|
|||
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
const res = await fetch(`/api/invoices/${id}`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
|
|
@ -1082,7 +1082,7 @@ export default function Review() {
|
|||
|
||||
const updateLineItemMutation = useMutation({
|
||||
mutationFn: async ({ itemId, data }: { itemId: number; data: Partial<LineItem> }) => {
|
||||
const res = await fetch(`/api/invoices/${id}/line-items/${itemId}`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}/line-items/${itemId}`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
|
|
@ -1104,7 +1104,7 @@ export default function Review() {
|
|||
|
||||
const createLineItemMutation = useMutation({
|
||||
mutationFn: async (data: Partial<LineItem>) => {
|
||||
const res = await fetch(`/api/invoices/${id}/line-items`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}/line-items`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
|
|
@ -1125,7 +1125,7 @@ export default function Review() {
|
|||
|
||||
const deleteLineItemMutation = useMutation({
|
||||
mutationFn: async (itemId: number) => {
|
||||
const res = await fetch(`/api/invoices/${id}/line-items/${itemId}`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}/line-items/${itemId}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
|
|
@ -1143,7 +1143,7 @@ export default function Review() {
|
|||
|
||||
const saveDefinitionMutation = useMutation({
|
||||
mutationFn: async ({ itemId, portionDesc }: { itemId: number; portionDesc?: string }) => {
|
||||
const res = await fetch(`/api/invoices/${id}/line-items/${itemId}/save-definition`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}/line-items/${itemId}/save-definition`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
|
|
@ -1161,7 +1161,7 @@ export default function Review() {
|
|||
|
||||
const createSupplierMutation = useMutation({
|
||||
mutationFn: async (name: string) => {
|
||||
const res = await fetch('/api/suppliers/', {
|
||||
const res = await fetch('/kitchen/api/suppliers/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
|
|
@ -1182,7 +1182,7 @@ export default function Review() {
|
|||
|
||||
const addAliasMutation = useMutation({
|
||||
mutationFn: async ({ supplierId, alias, invoiceId }: { supplierId: number; alias: string; invoiceId?: number }) => {
|
||||
const res = await fetch(`/api/suppliers/${supplierId}/aliases`, {
|
||||
const res = await fetch(`/kitchen/api/suppliers/${supplierId}/aliases`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
|
|
@ -1201,7 +1201,7 @@ export default function Review() {
|
|||
|
||||
const addDescriptionAliasMutation = useMutation({
|
||||
mutationFn: async ({ sourceId, alias }: { sourceId: number; alias: string }) => {
|
||||
const res = await fetch(`/api/ingredients/sources/${sourceId}/aliases`, {
|
||||
const res = await fetch(`/kitchen/api/ingredients/sources/${sourceId}/aliases`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
|
|
@ -1228,7 +1228,7 @@ export default function Review() {
|
|||
// PO link/unlink handlers
|
||||
const handleLinkPo = async (poId: number) => {
|
||||
try {
|
||||
const res = await fetch(`/api/purchase-orders/${poId}/link`, {
|
||||
const res = await fetch(`/kitchen/api/purchase-orders/${poId}/link`, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ invoice_id: parseInt(id!) }),
|
||||
|
|
@ -1242,7 +1242,7 @@ export default function Review() {
|
|||
|
||||
const handleUnlinkPo = async (poId: number) => {
|
||||
try {
|
||||
const res = await fetch(`/api/purchase-orders/${poId}/unlink`, {
|
||||
const res = await fetch(`/kitchen/api/purchase-orders/${poId}/unlink`, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
|
|
@ -1386,7 +1386,7 @@ export default function Review() {
|
|||
setAdminOperationResult(null)
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/invoices/${id}/mark-dext-sent`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}/mark-dext-sent`, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
|
|
@ -1423,7 +1423,7 @@ export default function Review() {
|
|||
setAdminOperationResult(null)
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/invoices/${id}/reprocess`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}/reprocess`, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
|
|
@ -1457,7 +1457,7 @@ export default function Review() {
|
|||
setShowDatePickerModal(true)
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/invoices/${id}/parse-dates`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}/parse-dates`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
|
||||
|
|
@ -1485,7 +1485,7 @@ export default function Review() {
|
|||
setInvoiceNumberExamples([])
|
||||
setShowInvoiceNumberModal(true)
|
||||
try {
|
||||
const res = await fetch(`/api/invoices/${id}/parse-invoice-number`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}/parse-invoice-number`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to search for invoice number')
|
||||
|
|
@ -1513,7 +1513,7 @@ export default function Review() {
|
|||
setAdminOperationResult(null)
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/invoices/${id}/resend-to-azure`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}/resend-to-azure`, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
|
|
@ -1532,7 +1532,7 @@ export default function Review() {
|
|||
// Poll for completion
|
||||
const pollInterval = setInterval(async () => {
|
||||
try {
|
||||
const checkRes = await fetch(`/api/invoices/${id}`, {
|
||||
const checkRes = await fetch(`/kitchen/api/invoices/${id}`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (checkRes.ok) {
|
||||
|
|
@ -1565,7 +1565,7 @@ export default function Review() {
|
|||
setAdminOperationResult(null)
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/invoices/${id}/regenerate-highlights`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}/regenerate-highlights`, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
|
|
@ -1756,7 +1756,7 @@ export default function Review() {
|
|||
if (!query || query.length < 2) return
|
||||
setSearchLoading(true)
|
||||
try {
|
||||
const res = await fetch('/api/invoices/line-items/search', {
|
||||
const res = await fetch('/kitchen/api/invoices/line-items/search', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
|
@ -1781,7 +1781,7 @@ export default function Review() {
|
|||
try {
|
||||
// Update all line items
|
||||
const promises = lineItems.map(item =>
|
||||
fetch(`/api/invoices/${id}/line-items/${item.id}`, {
|
||||
fetch(`/kitchen/api/invoices/${id}/line-items/${item.id}`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
|
|
@ -1805,7 +1805,7 @@ export default function Review() {
|
|||
setAiMatchLoading(true)
|
||||
setAiMatchResults([])
|
||||
try {
|
||||
const res = await fetch(`/api/ingredients/ai-match?description=${encodeURIComponent(description)}`, {
|
||||
const res = await fetch(`/kitchen/api/ingredients/ai-match?description=${encodeURIComponent(description)}`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (res.ok) {
|
||||
|
|
@ -1827,7 +1827,7 @@ export default function Review() {
|
|||
setAiDismissedCorrections(new Set())
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/invoices/${id}/ai-assist`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}/ai-assist`, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
|
|
@ -1906,7 +1906,7 @@ export default function Review() {
|
|||
// Fetch saved definition
|
||||
setDefinitionLoading(true)
|
||||
try {
|
||||
const res = await fetch(`/api/invoices/${id}/line-items/${item.id}/definition`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}/line-items/${item.id}/definition`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (res.ok) {
|
||||
|
|
@ -1927,7 +1927,7 @@ export default function Review() {
|
|||
if (!item.pack_quantity && !item.unit_size) {
|
||||
setAiPackSizeLoading(true)
|
||||
try {
|
||||
const packRes = await fetch(`/api/invoices/${id}/line-items/${item.id}/ai-pack-size`, {
|
||||
const packRes = await fetch(`/kitchen/api/invoices/${id}/line-items/${item.id}/ai-pack-size`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (packRes.ok) {
|
||||
|
|
@ -1961,7 +1961,7 @@ export default function Review() {
|
|||
}
|
||||
setIngredientSearchLoading(true)
|
||||
try {
|
||||
const res = await fetch(`/api/ingredients/suggest?description=${encodeURIComponent(query)}`, {
|
||||
const res = await fetch(`/kitchen/api/ingredients/suggest?description=${encodeURIComponent(query)}`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (res.ok) {
|
||||
|
|
@ -2053,7 +2053,7 @@ export default function Review() {
|
|||
if (selectedIngredientId) {
|
||||
try {
|
||||
// Set ingredient_id on line item
|
||||
await fetch(`/api/invoices/${id}/line-items/${itemId}`, {
|
||||
await fetch(`/kitchen/api/invoices/${id}/line-items/${itemId}`, {
|
||||
method: 'PATCH',
|
||||
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ ingredient_id: selectedIngredientId }),
|
||||
|
|
@ -2081,7 +2081,7 @@ export default function Review() {
|
|||
if (id) {
|
||||
sourceData.invoice_id = parseInt(id as string)
|
||||
}
|
||||
const srcRes = await fetch(`/api/ingredients/${selectedIngredientId}/sources`, {
|
||||
const srcRes = await fetch(`/kitchen/api/ingredients/${selectedIngredientId}/sources`, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(sourceData),
|
||||
|
|
@ -2610,7 +2610,7 @@ export default function Review() {
|
|||
)}
|
||||
{isPDF && imageUrl && (
|
||||
<a
|
||||
href={`/api/invoices/${id}/file?token=${encodeURIComponent(token || '')}`}
|
||||
href={`/kitchen/api/invoices/${id}/file?token=${encodeURIComponent(token || '')}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
style={styles.openPdfLink}
|
||||
|
|
@ -3092,7 +3092,7 @@ export default function Review() {
|
|||
onChange={(e) => setInvoiceNotes(e.target.value)}
|
||||
onBlur={async () => {
|
||||
try {
|
||||
await fetch(`/api/invoices/${id}`, {
|
||||
await fetch(`/kitchen/api/invoices/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
|
@ -4673,7 +4673,7 @@ export default function Review() {
|
|||
<button
|
||||
onClick={async () => {
|
||||
try {
|
||||
const res = await fetch(`/api/invoices/${id}/send-to-dext`, {
|
||||
const res = await fetch(`/kitchen/api/invoices/${id}/send-to-dext`, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue