diff --git a/README.md b/README.md index 631e387a..c62c5f0a 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,22 @@ Log into localhost with the credentials in the "Key Credentials" document. +5. Offline Setup + Change .env.local for the following variables (note that IP Address should be your static IP): + + ``` + NEXT_PUBLIC_OFFLINE='OFFLINE' + NEXT_PUBLIC_API_URL='https://192.168.1.100:3000/api/v1' + ``` + + Run the following command to start offline + + ``` + pnpm offline + ``` + + Refer to BackEnd offline Setup + ## Technology used 1. Node Version Manager [https://github.com/nvm-sh/nvm] diff --git a/context/VillageContext.js b/context/VillageContext.js index a29d5e22..aaf229b0 100644 --- a/context/VillageContext.js +++ b/context/VillageContext.js @@ -6,10 +6,11 @@ export const VillageContext = createContext(); export const useLoading = () => useContext(LoadingContext); export const VillageProvider = ({ children }) => { - const [village, setVillageState] = useState(undefined); + const [village, setVillageState] = useState('ALL'); useEffect(() => { - setVillageState(localStorage.getItem('village')); + const cachedVillage = localStorage.getItem('village'); + cachedVillage && setVillageState(cachedVillage); }, []); function setVillage(village) { diff --git a/pages/records/index.js b/pages/records/index.js index 9571fee9..d32a0a32 100644 --- a/pages/records/index.js +++ b/pages/records/index.js @@ -75,6 +75,7 @@ function PatientList() { useEffect(() => { filterPatients(); + setCurrentPage(1); }, [patientSearch, villageCode, patients]); function handleSearchChange(e) { diff --git a/pages/records/patient-consultation/index.js b/pages/records/patient-consultation/index.js index b56a0878..becc7253 100644 --- a/pages/records/patient-consultation/index.js +++ b/pages/records/patient-consultation/index.js @@ -267,7 +267,7 @@ const PatientConsultation = () => { } } - function submitNewOrder() { + async function submitNewOrder() { // Non-existent medication check: check if orderFormDetails.medicine (which is the id) is === 0 (which is the default value in the state obj) if (orderFormDetails.medicine === 0) { toast.error( @@ -301,6 +301,29 @@ const PatientConsultation = () => { return; } + // get pending quantity of medicine requested + const pendingQuantity = await axiosInstance + .get(`/medications/${orderFormDetails.medicine}?order_status=PENDING`) + .then(res => res.data.pending_quantity); + + console.log(pendingQuantity, quantityStockMedication); + // Alert when (pending order + current_order) > stock + if ( + -pendingQuantity + Number(orderFormDetails.quantity) > + quantityStockMedication + ) { + const alertResult = confirm(` + Warning (can ignore if ok) + Potentially Insufficient Stock! + Currently Requesting: ${orderFormDetails.quantity} + Total Potential Pending: ${-pendingQuantity} + Potentially Remaining: ${quantityStockMedication} - ${-pendingQuantity} = ${quantityStockMedication + pendingQuantity} + `); + if (!alertResult) { + return; + } + } + const index = orders.findIndex( order => order.medicine === orderFormDetails.medicine );