This commit is contained in:
@@ -101,6 +101,8 @@ const UpdateCustomer = () => {
|
||||
const [dischargeConfirmReasonOther, setDischargeConfirmReasonOther] = useState('');
|
||||
const [isDischarging, setIsDischarging] = useState(false);
|
||||
const [isReactivating, setIsReactivating] = useState(false);
|
||||
const [canDischargeCustomer, setCanDischargeCustomer] = useState(AuthService.canDischargeCustomer());
|
||||
const [canReactivateCustomer, setCanReactivateCustomer] = useState(AuthService.canReactivateCustomer());
|
||||
|
||||
// Care & Services
|
||||
const [dietaryRestrictions, setDietaryRestrictions] = useState([]);
|
||||
@@ -200,22 +202,47 @@ const UpdateCustomer = () => {
|
||||
}, [activeTab]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!AuthService.canEditAnyCustomerTab()) {
|
||||
window.alert('You haven\'t login yet OR this user does not have access to this page. Please change an admin account to login.')
|
||||
AuthService.logout();
|
||||
navigate(`/login`);
|
||||
}
|
||||
if (!currentCustomer) {
|
||||
CustomerService.getCustomer(urlParams.id).then((data) => {
|
||||
setCurrentCustomer(data.data);
|
||||
})
|
||||
}
|
||||
ResourceService.getAll('pharmacy').then(data => {
|
||||
setPharmacies(data.data);
|
||||
});
|
||||
ResourceService.getAll('provider').then(data => {
|
||||
setProviders(data.data);
|
||||
});
|
||||
let isMounted = true;
|
||||
const initPage = async () => {
|
||||
try {
|
||||
// Re-check permissions whenever Update Customer loads.
|
||||
await AuthService.refreshCurrentUserPermissions();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
} finally {
|
||||
if (!isMounted) return;
|
||||
setCanDischargeCustomer(AuthService.canDischargeCustomer());
|
||||
setCanReactivateCustomer(AuthService.canReactivateCustomer());
|
||||
}
|
||||
|
||||
if (!AuthService.canEditAnyCustomerTab()) {
|
||||
window.alert('You haven\'t login yet OR this user does not have access to this page. Please change an admin account to login.')
|
||||
AuthService.logout();
|
||||
navigate(`/login`);
|
||||
return;
|
||||
}
|
||||
if (!currentCustomer) {
|
||||
CustomerService.getCustomer(urlParams.id).then((data) => {
|
||||
if (isMounted) {
|
||||
setCurrentCustomer(data.data);
|
||||
}
|
||||
})
|
||||
}
|
||||
ResourceService.getAll('pharmacy').then(data => {
|
||||
if (isMounted) {
|
||||
setPharmacies(data.data);
|
||||
}
|
||||
});
|
||||
ResourceService.getAll('provider').then(data => {
|
||||
if (isMounted) {
|
||||
setProviders(data.data);
|
||||
}
|
||||
});
|
||||
};
|
||||
initPage();
|
||||
return () => {
|
||||
isMounted = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const formatDateForBackend = (date) => {
|
||||
@@ -251,6 +278,7 @@ const UpdateCustomer = () => {
|
||||
};
|
||||
|
||||
const handleDischarge = async () => {
|
||||
if (!canDischargeCustomer) return;
|
||||
if (!dischargeConfirmDate || !dischargeConfirmReason) {
|
||||
alert('Please fill in Discharge Date and Discharge Reason.');
|
||||
return;
|
||||
@@ -285,6 +313,7 @@ const UpdateCustomer = () => {
|
||||
};
|
||||
|
||||
const handleReactivate = async () => {
|
||||
if (!canReactivateCustomer) return;
|
||||
if (!currentCustomer?.id) return;
|
||||
|
||||
setIsReactivating(true);
|
||||
@@ -1320,7 +1349,7 @@ const UpdateCustomer = () => {
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{!isCustomerActive() && AuthService.canReactivateCustomer() && (
|
||||
{!isCustomerActive() && canReactivateCustomer && (
|
||||
<div style={{ marginTop: '16px' }}>
|
||||
<button className="btn btn-warning btn-sm" onClick={handleReactivate} disabled={isReactivating}>
|
||||
<BoxArrowRight className="me-2" size={16}></BoxArrowRight>{isReactivating ? 'Reactivating...' : 'Reactivate Customer'}
|
||||
@@ -1771,7 +1800,7 @@ const UpdateCustomer = () => {
|
||||
</Tab>}
|
||||
|
||||
</Tabs>
|
||||
{isCustomerActive() && showDischargeButton && AuthService.canDischargeCustomer() && (
|
||||
{isCustomerActive() && showDischargeButton && canDischargeCustomer && (
|
||||
<div className="list-func-panel">
|
||||
<button className="btn btn-warning btn-sm" onClick={openDischargeConfirmModal}>
|
||||
<BoxArrowRight className="me-2" size={16}></BoxArrowRight>Discharge Customer
|
||||
|
||||
Reference in New Issue
Block a user