-
Notifications
You must be signed in to change notification settings - Fork 1
Initial commit #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Initial commit #63
Changes from all commits
73d1a08
24e7860
9aa8b42
4873dd0
f333f1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,17 @@ | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { itemsApi } from '../api/items.api'; | ||
| import { publicItemsApi, itemsApi } from '../api/items.api'; | ||
| import type { ItemFilter } from '../lib/filters'; | ||
|
|
||
| export const useItems = (filters?: ItemFilter) => { | ||
| export const usePublicItems = (filters?: ItemFilter) => { | ||
| return useQuery({ | ||
| queryKey: ['items', 'list', filters], | ||
| queryFn: () => itemsApi.getAll(filters), // Use the updated `itemsApi.getAll` | ||
| queryKey: ['public-items', filters], | ||
| queryFn: () => publicItemsApi.getAll(filters), | ||
| }); | ||
| }; | ||
|
|
||
| export const useAdminItems = (filters?: ItemFilter) => { | ||
| return useQuery({ | ||
| queryKey: ['admin-items', filters], | ||
| queryFn: () => itemsApi.getAll(filters), | ||
| }); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,107 @@ | ||
| // Collection Items API calls | ||
| import apiClient from './apiClient'; | ||
| import type { PublicCollectionItem } from '../lib/types'; | ||
| import type { | ||
| ItemType, | ||
| ItemStatus, | ||
| PublicCollectionItem, | ||
| AdminCollectionItem, | ||
| } from '../lib/types'; | ||
|
|
||
| import type { ItemFilter } from '../lib/filters'; | ||
|
|
||
| export interface CreateItemData { | ||
| item_code: string; | ||
| title: string; | ||
| platform: string; | ||
| description: string; | ||
| item_type: ItemType; | ||
| working_condition: boolean; | ||
| status: ItemStatus; | ||
| current_location: number; | ||
| is_public_visible: boolean; | ||
| is_on_floor: boolean; | ||
| box: number | null; | ||
| } | ||
|
|
||
| export type UpdateItemData = Partial<CreateItemData>; | ||
|
|
||
| export const itemsApi = { | ||
| // ADMIN ONLY | ||
|
|
||
| getAll: async (params?: ItemFilter): Promise<AdminCollectionItem[]> => { | ||
| const queryParams: Record<string, string> = {}; | ||
|
|
||
| if (params?.platform) queryParams.platform = params.platform; | ||
| if (params?.is_on_floor !== undefined && params?.is_on_floor !== null) { | ||
| queryParams.is_on_floor = params.is_on_floor ? 'true' : 'false'; | ||
| } | ||
| if (params?.search) queryParams.search = params.search; | ||
| if (params?.ordering) queryParams.ordering = params.ordering; | ||
| if (params?.item_type) queryParams.item_type = params.item_type; | ||
| if (params?.status) queryParams.status = params.status; | ||
| if (params?.location_type) queryParams.location_type = params.location_type; | ||
|
|
||
| queryParams.page_size = '10000'; | ||
|
|
||
| const response = await apiClient.get('/inventory/items/', { | ||
| params: queryParams, | ||
| }); | ||
|
|
||
| const data = response.data; | ||
|
|
||
| if (Array.isArray(data)) return data; | ||
| if (data?.results && Array.isArray(data.results)) return data.results; | ||
| return []; | ||
| }, | ||
|
|
||
| getById: async (id: string | number): Promise<AdminCollectionItem> => { | ||
| const response = await apiClient.get(`/inventory/items/${id}/`); | ||
Edwz208 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return response.data; | ||
|
Comment on lines
+30
to
+58
|
||
| }, | ||
|
|
||
| create: async (data: CreateItemData): Promise<AdminCollectionItem> => { | ||
| const response = await apiClient.post('/inventory/items/', data); | ||
| return response.data; | ||
| }, | ||
|
|
||
| partialUpdate: async ( | ||
| id: string | number, | ||
| data: UpdateItemData | ||
| ): Promise<AdminCollectionItem> => { | ||
| const response = await apiClient.patch(`/inventory/items/${id}/`, data); | ||
| return response.data; | ||
| }, | ||
| }; | ||
|
|
||
|
|
||
| export const publicItemsApi = { | ||
| getAll: async (params?: ItemFilter): Promise<PublicCollectionItem[]> => { | ||
| const queryParams: Record<string, string> = {}; | ||
|
|
||
| if (params?.platform) queryParams.platform = params.platform; | ||
| if (params?.is_on_floor !== undefined && params?.is_on_floor !== null) | ||
| if (params?.is_on_floor !== undefined && params?.is_on_floor !== null) { | ||
| queryParams.is_on_floor = params.is_on_floor ? 'true' : 'false'; | ||
| } | ||
| if (params?.search) queryParams.search = params.search; | ||
| if (params?.ordering) queryParams.ordering = params.ordering; | ||
| if (params?.item_type) queryParams.item_type = params.item_type; | ||
| if (params?.status) queryParams.status = params.status; | ||
| if (params?.location_type) queryParams.location_type = params.location_type; | ||
|
|
||
| // Fetch all items by setting a large page size | ||
|
|
||
| queryParams.page_size = '10000'; | ||
|
|
||
| const response = await apiClient.get('/inventory/public/items/', { params: queryParams }); | ||
| return response.data.results ?? response.data; | ||
| const response = await apiClient.get('/inventory/public/items/', { | ||
| params: queryParams, | ||
| }); | ||
|
|
||
| const data = response.data; | ||
|
|
||
| if (Array.isArray(data)) return data; | ||
| if (data?.results && Array.isArray(data.results)) return data.results; | ||
| return []; | ||
| }, | ||
|
|
||
| getById: async (id: string | number): Promise<PublicCollectionItem> => { | ||
| const response = await apiClient.get(`/inventory/public/items/${id}/`); | ||
| return response.data; | ||
| } | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| function DetailRow({ label, value }: { label: string; value: string }) { | ||
| return ( | ||
| <div className="flex items-center justify-between px-4 py-3"> | ||
| <span className="text-xs font-semibold text-secondary tracking-wide">{label}</span> | ||
| <span className="text-sm text-primary">{value}</span> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default DetailRow; |
Uh oh!
There was an error while loading. Please reload this page.