changes in request steps - #202
Conversation
📝 WalkthroughWalkthroughThe PR introduces an amount field across the new request form workflow, refactors form state management to use a centralized store with multiple setter helpers, removes tenant selection functionality from Step 2, and extends the ServiceRequest type to include an optional amount field. Changes
Sequence DiagramsequenceDiagram
participant User
participant Step1 as UserStep1RequestForm
participant Hook as useNewRequestForm
participant Store as RequestStore
participant Step3 as UserNewRequest (Submit)
participant API as Backend API
User->>Step1: Enter amount value
Step1->>Step1: handleChange(amount)
Step1->>Hook: onNext({amount, ...formData})
Hook->>Store: setNewRequestForm({amount})
Store->>Store: Update newRequestForm.amount
Hook->>Hook: setAmount(amount)
User->>Step3: Complete form & submit
Step3->>Hook: useNewRequestForm()
Hook->>Store: Read newRequestForm state
Store-->>Hook: Return form data with amount
Hook->>Hook: Convert amount to number
Hook->>API: POST newRequest(payload with amount)
API-->>Hook: Success response
Hook->>Store: resetNewRequestForm()
Store->>Store: Reset to defaults
Hook-->>Step3: Navigate with success state
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/pages/userdashboard/features/Requests/hooks/useNewRequestForm.ts (1)
238-270:⚠️ Potential issue | 🟡 MinorAdd validation to prevent NaN in amount parsing.
parseFloaton a non-numeric string (e.g.,"abc") returnsNaN, which would then propagate into the request payload. Although the HTML input usestype="number", defensive validation in the hook prevents data corruption from store inconsistencies or programmatic setters.🛠️ Suggested guard
- const newRequest: ServiceRequest & { attachmentDataUrls?: string[]; videoDataUrl?: string | null } = { + const parsedAmount = amount !== "" ? Number.parseFloat(amount) : undefined; + if (parsedAmount !== undefined && !Number.isFinite(parsedAmount)) { + setSubmissionError("Amount must be a valid number."); + setIsSubmitting(false); + return false; + } + const newRequest: ServiceRequest & { attachmentDataUrls?: string[]; videoDataUrl?: string | null } = { ... - amount: amount ? parseFloat(amount) : undefined, + amount: parsedAmount, ... };
🤖 Fix all issues with AI agents
In
`@src/pages/userdashboard/features/Requests/components/UserStep1RequestForm.tsx`:
- Around line 24-26: The amount field is shown as required but not validated;
update the UserStep1RequestForm component to enforce validation for the amount
field (e.g., in the form schema or validation logic used by the component) by
making 'amount' required and adding a numeric/min constraint (greater than 0)
and show a clear error message on submit; ensure the asterisk/label aligns with
this rule, and apply the same fix where 'details'/'amount' are initialized or
validated (references: the 'amount' and 'details' fields in the
UserStep1RequestForm initialization and the component's submit/validation
handlers such as any 'onSubmit'/'handleSubmit' or validation schema used around
those ranges).
🧹 Nitpick comments (2)
src/pages/userdashboard/features/Requests/store/requestStore.ts (2)
14-38: Tighten availability typing to match shared models.Using
any[]weakens type safety versusAvailabilityOption[].♻️ Proposed type refinement
-import type { RequestFilters, ServiceRequest } from '../../../utils/types'; +import type { AvailabilityOption, RequestFilters, ServiceRequest } from '../../../utils/types'; newRequestForm: { ... - availability: any[]; + availability: AvailabilityOption[]; ... };
176-232: Avoid duplicated default form state.The default
newRequestFormobject is defined twice (initial state + reset), which risks drift.♻️ Suggested consolidation
+const defaultNewRequestForm = { + currentStep: 1, + selectedCategory: null, + selectedSubCategory: null, + selectedProblem: null, + finalDetail: null, + selectedEquipment: null, + equipmentSerial: null, + equipmentCondition: null, + title: "", + description: "", + location: "Gandhi Path Rd, Jaipur, RJ 302020", + property: "1", + authorization: null, + authCode: "", + setUpDateTime: null, + dateDue: null, + materials: [], + availability: [{ id: 1, date: "", timeSlots: [] }], + priority: null, + attachments: [], + video: null, + pets: [], + amount: "", +}; + export const useRequestStore = create<RequestState>((set) => ({ ... - newRequestForm: { - ... - }, + newRequestForm: { ...defaultNewRequestForm }, ... resetNewRequestForm: () => set({ - newRequestForm: { - ... - } + newRequestForm: { ...defaultNewRequestForm } }),
| details: initialData?.details || '', | ||
| amount: initialData?.amount || '' | ||
| }); |
There was a problem hiding this comment.
Amount is marked required but not validated.
Either remove the asterisk or enforce required/min constraints to avoid inconsistent UX.
🛠️ Suggested validation alignment
- <label className="block text-sm font-bold text-gray-700 mb-2">Amount*</label>
+ <label className="block text-sm font-bold text-gray-700 mb-2">Amount</label>
<input
type="number"
value={formData.amount}
onChange={(e) => handleChange('amount', e.target.value)}
placeholder="Enter amount (e.g. 500)"
className="w-full px-4 py-3 bg-white rounded-md border-none outline-none placeholder-gray-400"
+ min="0"
+ step="0.01"
/>Also applies to: 42-44, 330-340
🤖 Prompt for AI Agents
In
`@src/pages/userdashboard/features/Requests/components/UserStep1RequestForm.tsx`
around lines 24 - 26, The amount field is shown as required but not validated;
update the UserStep1RequestForm component to enforce validation for the amount
field (e.g., in the form schema or validation logic used by the component) by
making 'amount' required and adding a numeric/min constraint (greater than 0)
and show a clear error message on submit; ensure the asterisk/label aligns with
this rule, and apply the same fix where 'details'/'amount' are initialized or
validated (references: the 'amount' and 'details' fields in the
UserStep1RequestForm initialization and the component's submit/validation
handlers such as any 'onSubmit'/'handleSubmit' or validation schema used around
those ranges).
Summary by CodeRabbit
New Features
Removed Features