1.7 KiB
1.7 KiB
Add Material Dialog — Toggle Tabs (Individual vs By Group)
Goal
Enhance the "Add Material to Task" dialog in Projects/Show.tsx with two tab-style modes:
- Individual — shows flat list of all available materials (current behavior)
- By Group — first pick a group, then material dropdown filters to only that group's materials
Proposed Changes
Backend
[MODIFY] ProjectController.php
- In
show(), loadmaterialGroupswith their materials eagerly:'materialGroups' => fn ($q) => $q->with('materials:id,ulid,name,unit,unit_cost')->withCount('materials'), - No new endpoints needed — all data is already available, just not nested
Frontend
[MODIFY] Projects/Show.tsx
- Add state:
materialMode: 'individual' | 'group'andselectedGroupId: string - Add toggle tabs above the material
Selectin the dialog:- Two buttons styled as tabs:
Individual|By Group
- Two buttons styled as tabs:
- When mode = 'individual': show
availableMaterialsin dropdown (current behavior) - When mode = 'group':
- Show a "Group"
Selectdropdown populated fromproject.material_groups - Below it, show the material
Selectfiltered toselectedGroup.materials
- Show a "Group"
- Reset
selectedGroupIdandmaterialForm.material_idwhen switching tabs - Update
GroupOptioninterface to include optionalmaterialsarray
Verification
- Switch between tabs → material list updates correctly
- Select a group → only its materials appear
- Submit works the same regardless of mode