@@ -3,6 +3,7 @@ import { X, PlusCircle } from 'lucide-react';
33import { createPurchase } from '../utils/googleSheets.js' ;
44import { getRefreshedAccessToken } from '../utils/googleAuth.js' ;
55import { useAlert } from './AlertContext' ;
6+ import GroupNameAutocomplete from './groups/GroupNameAutoComplete.jsx' ;
67
78const CATEGORIES = [
89 'Robot' ,
@@ -15,19 +16,37 @@ const CATEGORIES = [
1516 'Other'
1617] ;
1718
18- export default function RequestForm ( { user, onClose, onCreated, presetFields = { } } ) {
19+ export default function RequestForm ( { user, onClose, onCreated, presetFields = { } , existingPurchases = [ ] } ) {
1920 const { showError } = useAlert ( ) ;
21+
22+ // Get today's date in local timezone
23+ const getLocalDate = ( ) => {
24+ const today = new Date ( ) ;
25+ const localDate = new Date ( today . getTime ( ) - ( today . getTimezoneOffset ( ) * 60000 ) )
26+ . toISOString ( )
27+ . split ( 'T' ) [ 0 ] ;
28+ return localDate ;
29+ } ;
30+
31+ // Extract unique group names from existing purchases
32+ const existingGroups = [ ...new Set (
33+ existingPurchases
34+ . map ( p => p [ 'Group Name' ] )
35+ . filter ( name => name && name . trim ( ) !== '' )
36+ ) ] . sort ( ) ;
37+
2038 const [ newRequest , setNewRequest ] = useState ( {
2139 'Request ID' : '' ,
2240 'Item Description' : '' ,
2341 'Item Link' : '' ,
2442 'Category' : '' ,
43+ 'Group Name' : '' ,
2544 'Quantity' : '' ,
2645 'Unit Price' : '' ,
2746 'Shipping' : '' ,
2847 'Package Size' : '' ,
2948 'Comments' : '' ,
30- 'Date Requested' : new Date ( ) . toISOString ( ) . split ( 'T' ) [ 0 ] ,
49+ 'Date Requested' : getLocalDate ( ) ,
3150 'Requester' : 'N/A' ,
3251 'State' : 'Pending Approval' ,
3352 ...presetFields
@@ -51,7 +70,7 @@ export default function RequestForm({ user, onClose, onCreated, presetFields = {
5170
5271 const handleClose = ( ) => {
5372 setIsClosing ( true ) ;
54- setTimeout ( ( ) => onClose ( ) , 300 ) ; // Match animation duration
73+ setTimeout ( ( ) => onClose ( ) , 300 ) ;
5574 } ;
5675
5776 const handleCreateRequest = async ( ) => {
@@ -77,7 +96,6 @@ export default function RequestForm({ user, onClose, onCreated, presetFields = {
7796 } `}
7897 onClick = { handleClose }
7998 >
80- { /* Mobile: Full screen, Desktop: Modal */ }
8199 < div
82100 className = { `
83101 bg-white shadow-2xl w-full h-full overflow-y-auto
@@ -144,23 +162,37 @@ export default function RequestForm({ user, onClose, onCreated, presetFields = {
144162 />
145163 </ div >
146164
147- { /* Category */ }
148- < div >
149- < label className = "block text-sm font-semibold text-gray-700 mb-2" >
150- Category < span className = "text-red-500" > *</ span >
151- </ label >
152- < select
153- value = { newRequest [ 'Category' ] }
154- onChange = { ( e ) =>
155- setNewRequest ( prev => ( { ...prev , 'Category' : e . target . value } ) )
156- }
157- className = "w-full border border-gray-300 rounded-lg px-4 py-3 focus:ring-2 focus:ring-green-500 focus:border-green-500 text-gray-700 transition text-base"
158- >
159- < option value = "" > Select a category</ option >
160- { CATEGORIES . map ( cat => (
161- < option key = { cat } value = { cat } > { cat } </ option >
162- ) ) }
163- </ select >
165+ { /* Category and Group Name */ }
166+ < div className = "grid grid-cols-1 sm:grid-cols-2 gap-4" >
167+ < div >
168+ < label className = "block text-sm font-semibold text-gray-700 mb-2" >
169+ Category < span className = "text-red-500" > *</ span >
170+ </ label >
171+ < select
172+ value = { newRequest [ 'Category' ] }
173+ onChange = { ( e ) =>
174+ setNewRequest ( prev => ( { ...prev , 'Category' : e . target . value } ) )
175+ }
176+ className = "w-full border border-gray-300 rounded-lg px-4 py-3 focus:ring-2 focus:ring-green-500 focus:border-green-500 text-gray-700 transition text-base"
177+ >
178+ < option value = "" > Select a category</ option >
179+ { CATEGORIES . map ( cat => (
180+ < option key = { cat } value = { cat } > { cat } </ option >
181+ ) ) }
182+ </ select >
183+ </ div >
184+
185+ < div >
186+ < label className = "block text-sm font-semibold text-gray-700 mb-2" >
187+ Group Name < span className = "text-gray-400 text-xs font-normal" > (Optional)</ span >
188+ </ label >
189+ < GroupNameAutocomplete
190+ value = { newRequest [ 'Group Name' ] }
191+ onChange = { ( value ) => setNewRequest ( prev => ( { ...prev , 'Group Name' : value } ) ) }
192+ existingGroups = { existingGroups }
193+ placeholder = "e.g., Robot Build 2025"
194+ />
195+ </ div >
164196 </ div >
165197
166198 { /* Quantity and Unit Price */ }
0 commit comments