updates on the rider and the rider substitution page regarding the crud operations and more change outthere

This commit is contained in:
2026-06-22 12:17:07 +05:30
parent 4823df08a3
commit 94ad8ab262
2 changed files with 287 additions and 52 deletions

View File

@@ -45,11 +45,15 @@ const STATUS_META = {
};
export default function RiderSubstitution({
appId,
rows,
allRidersList,
substituteRidersList,
substituteAssignments,
handleAssignSubstitute,
onFinalizeSuccess,
selectedDate,
setSelectedDate,
DT,
BRAND,
edge,
@@ -58,7 +62,6 @@ export default function RiderSubstitution({
}) {
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
const [selectedDate, setSelectedDate] = useState(dayjs());
const [selectedBatch, setSelectedBatch] = useState('all');
const [isFinalizing, setIsFinalizing] = useState(false);
@@ -118,9 +121,8 @@ export default function RiderSubstitution({
}, [selectedDate]);
const filteredRows = React.useMemo(() => {
if (selectedBatch === 'all') return rows;
return rows?.filter((row) => getBatchForTime(row.starttime) === selectedBatch);
}, [rows, selectedBatch, getBatchForTime]);
return rows;
}, [rows]);
const hasAssignments = Object.values(substituteAssignments || {}).some(
(val) => val !== null && val !== undefined
@@ -129,8 +131,37 @@ export default function RiderSubstitution({
const handleFinalize = async () => {
setIsFinalizing(true);
try {
const rawTenantId = localStorage.getItem('tenantid');
const tenantId = (rawTenantId && rawTenantId !== 'undefined' && rawTenantId !== 'null') ? parseInt(rawTenantId, 10) : 44;
let partnerId = '';
try {
const rawLocs = localStorage.getItem('applocations');
if (rawLocs) {
const locs = JSON.parse(rawLocs);
const currentLoc = locs.find((l) => l.applocationid === appId);
if (currentLoc && currentLoc.partnerid) {
partnerId = currentLoc.partnerid;
} else {
const firstValidLoc = locs.find((l) => l.partnerid);
if (firstValidLoc && firstValidLoc.partnerid) {
partnerId = firstValidLoc.partnerid;
}
}
}
} catch (e) {
console.error('Error parsing applocations', e);
}
if (!partnerId) {
const savedPartnerId = localStorage.getItem('partnerid');
if (savedPartnerId && savedPartnerId !== 'undefined' && savedPartnerId !== 'null') {
partnerId = savedPartnerId;
}
}
if (!partnerId || partnerId === '0' || partnerId === 0) {
partnerId = 44;
}
const tenantId = parseInt(partnerId, 10);
const substitutions = Object.entries(substituteAssignments || {})
.filter((entry) => entry[1] !== null && entry[1] !== undefined)
@@ -143,7 +174,8 @@ export default function RiderSubstitution({
absent_rider_name: absentRider?.username || absentRider?.fullname || `Rider #${absentRiderId}`,
sub_rider_id: parseInt(subRider.userid, 10),
sub_rider_name: subRider.username || subRider.fullname || `Rider #${subRider.userid}`,
reason: "Scheduled"
reason: "Scheduled",
batch: selectedBatch
};
});
@@ -315,6 +347,8 @@ export default function RiderSubstitution({
filteredRows?.map((row, index) => {
const statusMeta = getRowStatusMeta(row);
const StatusIcon = statusMeta.icon;
const riderProfile = allRidersList?.find((r) => r.userid === row.userid);
const starttime = riderProfile?.starttime || row.starttime;
return (
<MobileCard
key={row.userid ?? index}
@@ -398,7 +432,7 @@ export default function RiderSubstitution({
<MobileField label="Substitute" full>
<Autocomplete
size="small"
disabled={isBatchDisabled(getBatchForTime(row.starttime))}
disabled={isBatchDisabled(getBatchForTime(starttime))}
options={substituteRidersList || []}
isOptionEqualToValue={(option, value) => option?.userid === value?.userid}
getOptionLabel={(option) => `${option.username || option.fullname || ''} (#${option.userid})`}
@@ -471,6 +505,8 @@ export default function RiderSubstitution({
filteredRows?.map((row, index) => {
const statusMeta = getRowStatusMeta(row);
const StatusIcon = statusMeta.icon;
const riderProfile = allRidersList?.find((r) => r.userid === row.userid);
const starttime = riderProfile?.starttime || row.starttime;
return (
<TableRow
key={row.userid ?? index}
@@ -545,7 +581,7 @@ export default function RiderSubstitution({
<TableCell sx={{ minWidth: 220 }}>
<Autocomplete
size="small"
disabled={isBatchDisabled(getBatchForTime(row.starttime))}
disabled={isBatchDisabled(getBatchForTime(starttime))}
options={substituteRidersList || []}
isOptionEqualToValue={(option, value) => option?.userid === value?.userid}
getOptionLabel={(option) => `${option.username || option.fullname || ''} (#${option.userid})`}