feat: add hub selection to battery form and update data schema

This commit is contained in:
sazzadulalambd
2026-05-17 20:35:10 +06:00
parent 9370b71b25
commit aaf91255bb

View File

@@ -58,6 +58,8 @@ interface Battery {
assignedBikerName?: string;
currentStationId?: string;
currentStationName?: string;
hubId?: string;
hubName?: string;
lastMaintenance?: string;
nextMaintenance?: string;
bmsData?: BMSData;
@@ -254,6 +256,13 @@ const mockStations: SwapStation[] = [
{ id: 'SS-005', name: 'Mirpur Swap Station', location: 'Mirpur 1, Section 2' },
];
const hubs = [
{ id: 'HUB-001', name: 'JAIBEN Head Office' },
{ id: 'HUB-002', name: 'Banani Hub' },
{ id: 'HUB-003', name: 'Uttara Hub' },
{ id: 'HUB-004', name: 'Mirpur Hub' },
];
const statusColors: Record<string, string> = {
available: 'bg-green-100 text-green-700',
'in-use': 'bg-blue-100 text-blue-700',
@@ -789,12 +798,17 @@ function BatteryForm({ battery, onSave, onCancel }: { battery: Battery | null; o
voltage: 60,
purchaseDate: new Date().toISOString().split('T')[0],
purchasePrice: 0,
transactionMethod: 'cash',
autoJournal: true,
autoJournalSource: 'supplier',
warrantyExpiry: '',
status: 'available',
currentSoc: 100,
health: 100,
cycleCount: 0,
history: [],
hubId: '',
hubName: '',
});
const handleChange = (field: keyof Battery, value: any) => {
@@ -897,33 +911,23 @@ function BatteryForm({ battery, onSave, onCancel }: { battery: Battery | null; o
<option value="other">Other</option>
</select>
</div>
<div className="flex items-center gap-3">
<label className="flex items-center gap-2 cursor-pointer">
<input
type="checkbox"
checked={formData.autoJournal || false}
onChange={(e) => handleChange('autoJournal', e.target.checked)}
className="w-4 h-4 text-accent rounded border-slate-300 focus:ring-accent"
/>
<span className="text-sm text-slate-700">Auto-Journal Entry</span>
</label>
</div>
{formData.autoJournal && (
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Auto-Journal Source</label>
<label className="block text-sm font-medium text-slate-700 mb-1">Hub</label>
<select
value={formData.autoJournalSource || 'supplier'}
onChange={(e) => handleChange('autoJournalSource', e.target.value as any)}
value={formData.hubId || ''}
onChange={(e) => {
const hub = hubs.find(h => h.id === e.target.value);
handleChange('hubId', e.target.value);
handleChange('hubName', hub?.name || '');
}}
className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-accent"
>
<option value="supplier">Supplier Purchase</option>
<option value="import">Import</option>
<option value="internal">Internal Transfer</option>
<option value="transfer">Transfer</option>
<option value="other">Other</option>
<option value="">Select Hub...</option>
{hubs.map(hub => (
<option key={hub.id} value={hub.id}>{hub.name}</option>
))}
</select>
</div>
)}
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Warranty Expiry</label>
<input