This commit is contained in:
@@ -202,6 +202,7 @@ function App() {
|
||||
{/* <Route path="/" element={<Navigate replace to="/login" />} /> */}
|
||||
<Route path="/landing" element={<Landing />} />
|
||||
<Route path="/login" element={<Login setMenu={() => {setShowMenu(true)}}/>} />
|
||||
<Route path="/signature/:id" element={<DriverSignature/>} />
|
||||
<Route path="/" element={<Layout />}>
|
||||
<Route index element={<Home />} ></Route>
|
||||
<Route path="/trans-routes" element={<TransRoutes />}>
|
||||
@@ -222,7 +223,6 @@ function App() {
|
||||
<Route path="route-signature" element={<RouteSignatureList/>} />
|
||||
<Route path="route-report-with-signature/:id" element={<RouteReportWithSignature/>} />
|
||||
</Route>
|
||||
<Route path="/signature/:id" element={<DriverSignature/>} />
|
||||
<Route path="/vehicles" element={<CreateVehicle /> } />
|
||||
<Route path="/vehicles/edit/:id" element={<UpdateVehicle />} />
|
||||
<Route path="/vehicles/list" element={<VehicleList/> } />
|
||||
|
||||
@@ -73,6 +73,7 @@ const DashboardCustomersList = ({ additionalButtons, showBreadcrumb = false, tit
|
||||
const [avatarLoading, setAvatarLoading] = useState(false);
|
||||
const [customerAvatars, setCustomerAvatars] = useState({});
|
||||
const isAllCustomersPage = title === 'All Customers';
|
||||
const customerTabOrder = ['personalInfo', 'careServices', 'medicalInsurance', 'confidentialDetails', 'formSubmission'];
|
||||
const [columns, setColumns] = useState(getVisibleColumnsByPermission([
|
||||
{
|
||||
key: 'name',
|
||||
@@ -309,7 +310,11 @@ const DashboardCustomersList = ({ additionalButtons, showBreadcrumb = false, tit
|
||||
}
|
||||
|
||||
const goToEdit = (id) => {
|
||||
navigate(`/customers/edit/${id}`);
|
||||
const editableTab = AuthService.canEditCustomerTab('personalInfo')
|
||||
? 'personalInfo'
|
||||
: customerTabOrder.find((tabKey) => AuthService.canEditCustomerTab(tabKey));
|
||||
if (!editableTab) return;
|
||||
navigate(`/customers/edit/${id}?tab=${editableTab}&fromEdit=1`);
|
||||
}
|
||||
|
||||
const goToCreateNew = () => {
|
||||
@@ -396,7 +401,7 @@ const DashboardCustomersList = ({ additionalButtons, showBreadcrumb = false, tit
|
||||
/>
|
||||
)
|
||||
)}
|
||||
{AuthService.canEditAnyCustomerTab() && <PencilSquare size={16} className="clickable" onClick={() => isAllCustomersPage ? goToEdit(customer?.id) : goToView(customer?.id)} style={{ flexShrink: 0 }}></PencilSquare>}
|
||||
{AuthService.canEditAnyCustomerTab() && <PencilSquare size={16} className="clickable" onClick={() => goToEdit(customer?.id)} style={{ flexShrink: 0 }}></PencilSquare>}
|
||||
<span className="clickable" style={{ color: '#0066B1', textDecoration: 'underline', cursor: 'pointer' }} onClick={() => goToView(customer?.id)}>{customer?.name}</span>
|
||||
</div>
|
||||
</td>}
|
||||
|
||||
@@ -22,6 +22,8 @@ const RouteView = () => {
|
||||
const currentDriver = drivers.find(item => item.id === currentRoute?.driver);
|
||||
const [fallbackDriver, setFallbackDriver] = useState(undefined);
|
||||
const [showVehicleDetails, setShowVehicleDetails] = useState(false);
|
||||
const [showResetSignatureConfirmModal, setShowResetSignatureConfirmModal] = useState(false);
|
||||
const [isResettingSignature, setIsResettingSignature] = useState(false);
|
||||
const [signature, setSignature] = useState(undefined);
|
||||
const [signatureRequest, setSignatureRequest] = useState(undefined);
|
||||
const [routeStatusValue, setRouteStatusValue] = useState('');
|
||||
@@ -35,6 +37,7 @@ const RouteView = () => {
|
||||
const navigate = useNavigate();
|
||||
const resolvedDriverId = currentDriver?.id || fallbackDriver?.id || currentRoute?.driver;
|
||||
const resolvedDriverName = currentDriver?.name || fallbackDriver?.name || '';
|
||||
const isSignatureRequestActive = signatureRequest?.status === 'active';
|
||||
const routeStatusOptions = [
|
||||
{ value: '', label: 'Not Started' },
|
||||
{ value: ROUTE_STATUS.ENROUTE, label: 'En Route' },
|
||||
@@ -67,6 +70,13 @@ const RouteView = () => {
|
||||
const openModal = () => {
|
||||
setShowVehicleDetails(true);
|
||||
}
|
||||
const openResetSignatureConfirmModal = () => {
|
||||
setShowResetSignatureConfirmModal(true);
|
||||
}
|
||||
const closeResetSignatureConfirmModal = () => {
|
||||
if (isResettingSignature) return;
|
||||
setShowResetSignatureConfirmModal(false);
|
||||
}
|
||||
const getRelatedOutboundRoutesForThisView = () => {
|
||||
if (allRoutes.find(item => item.id === params.id)) {
|
||||
return allRoutes.filter(item => item.type==='outbound');
|
||||
@@ -113,6 +123,53 @@ const RouteView = () => {
|
||||
setSignatureRequest(data.data);
|
||||
})
|
||||
}
|
||||
const resetSignatureForResign = async () => {
|
||||
if (!currentRoute?.id || !currentRoute?.schedule_date) return;
|
||||
if (!resolvedDriverId && !signatureRequest?.driver_id) {
|
||||
window.alert('Driver is not assigned for this route.');
|
||||
return;
|
||||
}
|
||||
setIsResettingSignature(true);
|
||||
try {
|
||||
const dateArr = moment(currentRoute?.schedule_date)?.format('MM/DD/YYYY')?.split('/') || [];
|
||||
const month = dateArr[0];
|
||||
const day = dateArr[1];
|
||||
const candidateDriverIds = Array.from(new Set([
|
||||
resolvedDriverId,
|
||||
currentRoute?.driver,
|
||||
routeSnapshot?.driver,
|
||||
signatureRequest?.driver_id
|
||||
].filter(Boolean)));
|
||||
await Promise.all(candidateDriverIds.map((driverId) => {
|
||||
const signatureKey = `${currentRoute?.id}_${driverId}_${month}_${day}`;
|
||||
return CustomerService.deleteFile({ name: signatureKey }).catch(() => null);
|
||||
}));
|
||||
|
||||
if (signatureRequest?.id) {
|
||||
await SignatureRequestService.updateSignatureRequest(signatureRequest.id, { status: 'active' });
|
||||
const refreshedRequest = await SignatureRequestService.getSignatureRequestById(signatureRequest.id);
|
||||
setSignatureRequest(refreshedRequest?.data);
|
||||
} else {
|
||||
const newRequest = await SignatureRequestService.createNewSignatureRequest({
|
||||
driver_id: resolvedDriverId || currentRoute?.driver,
|
||||
driver_name: resolvedDriverName,
|
||||
route_id: currentRoute?.id,
|
||||
route_date: currentRoute?.schedule_date,
|
||||
route_name: currentRoute?.name,
|
||||
status: 'active',
|
||||
});
|
||||
setSignatureRequest(newRequest?.data);
|
||||
}
|
||||
setSignature(undefined);
|
||||
setShowResetSignatureConfirmModal(false);
|
||||
window.alert('Signature has been reset. Driver can sign again.');
|
||||
} catch (error) {
|
||||
console.error('Error resetting signature:', error);
|
||||
window.alert('Failed to reset signature. Please try again.');
|
||||
} finally {
|
||||
setIsResettingSignature(false);
|
||||
}
|
||||
}
|
||||
const saveRouteStatus = async () => {
|
||||
if (!currentRoute?.id || isSavingRouteStatus) return;
|
||||
try {
|
||||
@@ -359,14 +416,14 @@ const RouteView = () => {
|
||||
<div className="field-label">Driver Signature</div>
|
||||
<div className="field-value">
|
||||
{signature && <img width="100px" src={`data:image/jpg;base64, ${signature}`}/>}
|
||||
|
||||
{canEditRoutes && <button className="btn btn-sm btn-outline-danger ms-2" onClick={openResetSignatureConfirmModal}>Reset Signature</button>}
|
||||
</div>
|
||||
</div>}
|
||||
{!signature && !signatureRequest && <div className="field-body">
|
||||
{!signature && !isSignatureRequestActive && <div className="field-body">
|
||||
<div className="field-label">Signature Request</div>
|
||||
<div className="field-value"><button className="btn btn-sm btn-primary" onClick={() => generateSignatureRequest()}>Generate Signature Link For Driver</button></div>
|
||||
</div>}
|
||||
{!signature && signatureRequest && <div className="alert alert-success fade show mb-2 mt-2" role="alert">
|
||||
{!signature && isSignatureRequestActive && <div className="alert alert-success fade show mb-2 mt-2" role="alert">
|
||||
<div>Please send this to the driver to get signature:</div>
|
||||
<div>{`${window.location.origin}/signature/${signatureRequest?.id}`}</div>
|
||||
</div>}
|
||||
@@ -443,6 +500,22 @@ const RouteView = () => {
|
||||
</Button>
|
||||
</Modal.Footer>
|
||||
</Modal>
|
||||
<Modal show={showResetSignatureConfirmModal} onHide={closeResetSignatureConfirmModal}>
|
||||
<Modal.Header closeButton={!isResettingSignature}>
|
||||
<Modal.Title>Reset Driver Signature</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body>
|
||||
Are you sure you want to reset this signature? The driver will need to sign again.
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
<Button variant="secondary" onClick={closeResetSignatureConfirmModal} disabled={isResettingSignature}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button variant="danger" onClick={resetSignatureForResign} disabled={isResettingSignature}>
|
||||
{isResettingSignature ? 'Resetting...' : 'Confirm Reset'}
|
||||
</Button>
|
||||
</Modal.Footer>
|
||||
</Modal>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user