-
Notifications
You must be signed in to change notification settings - Fork 1
feat(frontend): enable edit item and improve mobile layout #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
Open
Edwz208
wants to merge
9
commits into
main
Choose a base branch
from
feature/enable-edit-item-and-mobile-optimization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
73d1a08
initial commit
Edwz208 24e7860
Modifications to the type parameters of frontend components to match …
Edwz208 9aa8b42
minor change to collection items
Edwz208 4873dd0
change to have a public and admin collection item type
Edwz208 f333f1e
edit item modal, modified catalogue pages to match backend and add mo…
Edwz208 3d1acce
Update frontend/src/components/items/EditItemModal.tsx
Edwz208 a175e90
Update frontend/src/components/layout/Header.css
Edwz208 f37ab32
modified to fix location display and navbar mobile decision
Edwz208 ab4fcd0
Merge branch 'main' into feature/enable-edit-item-and-mobile-optimiza…
qiuethan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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), | ||
| }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
Edwz208 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
|
|
||
| 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; | ||
| } | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.