Some checks failed
Deploy to Coolify / Deploy to Development (pull_request) Has been cancelled
Deploy to Coolify / Deploy to Production (pull_request) Has been cancelled
Deploy to Coolify / Code Quality (pull_request) Has been cancelled
Deploy to Coolify / Run Tests (pull_request) Has been cancelled
Deploy to Coolify / Deploy to Test (pull_request) Has been cancelled
Pull Request Checks / Validate PR (pull_request) Has been cancelled
Week 2 core inventory management: **Composables:** - useInventory: Full CRUD operations for inventory items - useUnits: Unit fetching and conversion helpers - useTags: Tag fetching and category filtering **Components:** - InventoryList (#18): Grid view with loading/empty/error states - InventoryCard: Item card with image, quantity controls, tags, expiry - AddItemForm (#19): Form with tag picker, unit selector, validation - EditItemModal (#20): Modal form for editing existing items - Delete functionality (#21): Confirm dialog + cascade tag cleanup **Features:** - Quantity quick-actions (+/- buttons on cards) - Auto-delete when quantity reaches zero - Expiry date tracking with color-coded warnings - Tag selection by category in add form - Responsive grid layout (1-4 columns) - Product image display from barcode cache - Form validation and loading states Closes #18, #19, #20, #21
54 lines
1.1 KiB
TypeScript
54 lines
1.1 KiB
TypeScript
export const useUnits = () => {
|
|
const supabase = useSupabase()
|
|
|
|
/**
|
|
* Get all units
|
|
*/
|
|
const getUnits = async () => {
|
|
const { data, error } = await supabase
|
|
.from('units')
|
|
.select('*')
|
|
.order('unit_type', { ascending: true })
|
|
.order('name', { ascending: true })
|
|
|
|
if (error) {
|
|
console.error('Error fetching units:', error)
|
|
return { data: null, error }
|
|
}
|
|
|
|
return { data, error: null }
|
|
}
|
|
|
|
/**
|
|
* Get default unit for a type
|
|
*/
|
|
const getDefaultUnit = async (unitType: 'weight' | 'volume' | 'count' | 'custom') => {
|
|
const { data, error } = await supabase
|
|
.from('units')
|
|
.select('*')
|
|
.eq('unit_type', unitType)
|
|
.eq('is_default', true)
|
|
.single()
|
|
|
|
if (error) {
|
|
console.error('Error fetching default unit:', error)
|
|
return { data: null, error }
|
|
}
|
|
|
|
return { data, error: null }
|
|
}
|
|
|
|
/**
|
|
* Convert quantity between units
|
|
*/
|
|
const convertUnit = (quantity: number, fromFactor: number, toFactor: number): number => {
|
|
return (quantity * fromFactor) / toFactor
|
|
}
|
|
|
|
return {
|
|
getUnits,
|
|
getDefaultUnit,
|
|
convertUnit
|
|
}
|
|
}
|