Skip to content

Commit

Permalink
Merge pull request #52 from egovernments/ISNE-223
Browse files Browse the repository at this point in the history
Isne 223: FSM - TQM Frontend Changes
  • Loading branch information
vinothrallapalli-eGov committed Sep 17, 2024
2 parents 9563212 + 57f8bf7 commit b0b1e79
Show file tree
Hide file tree
Showing 21 changed files with 4,006 additions and 1,395 deletions.
2 changes: 1 addition & 1 deletion frontend/micro-ui/web/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN apk update && apk upgrade
RUN apk add --no-cache git>2.30.0
RUN yarn add @upyog/digit-ui-libraries
RUN yarn add @upyog/digit-ui-module-pt
RUN yarn add @upyog/digit-ui-module-fsm
RUN yarn add @egovernments/digit-ui-module-fsm
RUN yarn add @upyog/digit-ui-module-tl
RUN yarn add @upyog/digit-ui-module-dss
RUN yarn add @upyog/digit-ui-module-mcollect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@upyog/digit-ui-module-bills": "1.8.0",
"@upyog/digit-ui-module-common": "1.8.0",
"@upyog/digit-ui-module-engagement": "1.8.0",
"@upyog/digit-ui-module-fsm": "1.8.4",
"@egovernments/digit-ui-module-fsm": "1.8.4-beta1",
"@upyog/digit-ui-module-mcollect": "1.8.0",
"@upyog/digit-ui-module-noc": "1.8.0",
"@upyog/digit-ui-module-obps": "1.8.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PGRReducers } from "@upyog/digit-ui-module-pgr";
import { PTModule, PTLinks, PTComponents } from "@upyog/digit-ui-module-pt";
import { MCollectModule, MCollectLinks } from "@upyog/digit-ui-module-mcollect";
// import { TLModule, TLLinks } from "@upyog/digit-ui-module-tl";
import { initFSMComponents } from "@upyog/digit-ui-module-fsm";
import { initFSMComponents } from "@egovernments/digit-ui-module-fsm";
import { initPGRComponents } from "@upyog/digit-ui-module-pgr";
import { initDSSComponents } from "@upyog/digit-ui-module-dss";
import { initHRMSComponents } from "@upyog/digit-ui-module-hrms";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useQuery } from "react-query";
import { FSMService } from "../../services/elements/FSM";

const useWorkerSearch = (args) => {
const { tenantId, params, details, config } = args;
console.log(tenantId, params, details,"sssss")
return useQuery(["FSM_WORKER_SEARCH", details], () => FSMService.workerSearch({ tenantId, params, details }), config);
};

export default useWorkerSearch;
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import usePGRTenants from "./pgr/useTenants";
import usePGRMDMS from "./pgr/useMDMS";
import useComplaintSubType from "./pgr/useComplaintSubType";
import useComplaintStatusCount from "./pgr/useComplaintStatusWithCount";
import useWorkerSearch from "./fsm/useWorkerSearch";

import useTenantsFSM from "./fsm/useTenants";
import useDesludging from "./fsm/useDesludging";
Expand Down Expand Up @@ -334,6 +335,7 @@ const fsm = {
useVehicleTripCreate,
useVendorSearch,
useAdvanceBalanceCalulation,
useWorkerSearch
};
const ptr = {
usePetMDMS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const Urls = {
updateDriver: "/vendor/driver/v1/_update",
vehicleTripCreate: "/vehicle/trip/v1/_create",
advanceBalanceCalculate: "/fsm-calculator/v1/_advancebalancecalculate",
workerSearch: "/individual/v1/_search",
},

payment: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,14 @@ export const FSMService = {
params: { tenantId, ...details },
auth: true,
}),
workerSearch: ({ tenantId, details, params }) =>
Request({
url: Urls.fsm.workerSearch,
data: details,
useCache: false,
userService: true,
method: "POST",
params: { tenantId, ...params },
auth: true,
}),
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@upyog/digit-ui-module-fsm",
"version": "1.8.4",
"name": "@egovernments/digit-ui-module-fsm",
"version": "1.8.4-beta1",
"license": "MIT",
"main": "dist/index.js",
"description": "Digit FSM Module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ import SelectTrips from "./pageComponents/SelectTrips";
import PlusMinusInput from "./pageComponents/PlusMinusInput";
import ConfirmationBox from "./components/Confirmation";
import SelectLocalityOrGramPanchayat from "./pageComponents/SelectLocalityOrGramPanchayat";
import AddWorker from "./pages/employee/FSMRegistry/Worker/AddWorker"
import EditWorker from "./pages/employee/FSMRegistry/Worker/EditWorker";
import WorkerDetails from "./pages/employee/FSMRegistry/Worker/WorkerDetails";

const FSMModule = ({ stateCode, userType, tenants }) => {
const moduleCode = "FSM";
Expand Down Expand Up @@ -219,6 +222,9 @@ const componentsToRegister = {
PlusMinusInput,
ConfirmationBox,
SelectLocalityOrGramPanchayat,
AddWorker,
EditWorker,
WorkerDetails,
};

export const initFSMComponents = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const popupActionBarStyles = {
justifyContent: 'space-around'
}

const ActionModal = ({ t, action, tenantId, state, id, closeModal, submitAction, actionData, module }) => {
const ActionModal = ({ t, action, tenantId, state, id, closeModal, submitAction, actionData, module, applicationDetails }) => {
const mobileView = Digit.Utils.browser.isMobile() ? true : false;
const { data: dsoData, isLoading: isDsoLoading, isSuccess: isDsoSuccess, error: dsoError } = Digit.Hooks.fsm.useDsoSearch(tenantId, { limit: '-1', status: 'ACTIVE' });
const { isLoading, isSuccess, isError, data: applicationData, error } = Digit.Hooks.fsm.useSearch(
Expand Down Expand Up @@ -130,6 +130,53 @@ const ActionModal = ({ t, action, tenantId, state, id, closeModal, submitAction,
const [fstpoRejectionReason, setFstpoRejectionReason] = useState();
const [noOfTrips, setNoOfTrips] = useState(null);

const [workers,setWorkers] = useState([]);
const [drivers,setDrivers] = useState([]);
const [selectedDriver,setSelectedDriver] = useState([]);
const [selectedWorkers,setSelectedWorkers] = useState([]);
const [vehicleDriverList, setVehicleDriverList] = useState([]);
const [vehicleDriver, setVehicleDriver] = useState(null);

const individualIds = applicationDetails?.dsoDetails?.workers?.map(worker => {
return worker?.individualId
})?.filter(id => id)

console.log(applicationDetails,"applicationDetails")

const {
data: workerData,
isLoading: isLoadingWorkers,
isSuccess: isSuccessWorkers,
error: isErrorWorkers,
refetch: refetchWorkers,
} = Digit.Hooks.fsm.useWorkerSearch({
tenantId,
details: {
Individual: {
// roleCodes: ['SANITATION_WORKER'],
tenantId,
id:individualIds
},
},
params: {
// ...paginationParms,
// name: searchParams?.name,
limit: 100,
offset: 0,
},
config: {
enabled: individualIds?.length > 0 ? true : false,
select: (data) => {
const result = data?.Individual?.map(ind => {return {givenName:ind?.name?.givenName,optionsKey:`${ind?.name?.givenName} / ${ind?.individualId}`,...ind}})?.filter(worker => worker?.userDetails?.roles?.some(role=> role?.code === "SANITATION_WORKER"))
const workersOutOfResult = result?.filter(worker => worker?.userDetails?.roles?.some(role=> role?.code === "SANITATION_HELPER"))
setWorkers(workersOutOfResult)
const drivers = result?.filter(worker => worker?.userDetails?.roles?.some(role=> role?.code === "FSM_DRIVER"))
setDrivers(drivers)
return result
},
},
});

const [defaultValues, setDefautValue] = useState({
capacity: vehicle?.capacity,
wasteCollected: vehicle?.capacity,
Expand Down Expand Up @@ -200,7 +247,9 @@ const ActionModal = ({ t, action, tenantId, state, id, closeModal, submitAction,
if (isSuccess && isDsoSuccess && applicationData && applicationData.dsoId) {
const [dso] = dsoData.filter((dso) => dso.id === applicationData.dsoId);
const tempList = dso?.vehicles?.filter((vehicle) => vehicle.capacity == applicationData?.vehicleCapacity);
const vehicleNoList = tempList.sort((a,b) => (a.registrationNumber > b.registrationNumber ? 1 : -1 ));
const vehicleNoList = tempList?.sort((a,b) => (a?.registrationNumber > b?.registrationNumber ? 1 : -1 ));
const tempDriverList = dso?.drivers
setVehicleDriverList(tempDriverList)
setVehicleNoList(vehicleNoList);
}
}, [isSuccess, isDsoSuccess]);
Expand Down Expand Up @@ -253,6 +302,14 @@ const ActionModal = ({ t, action, tenantId, state, id, closeModal, submitAction,
workflow.comments = data.comments ? state.code + "~" + data.comments : state.code;
}

function selectVehicleNo(vehicleNo) {
setVehicleNo(vehicleNo);
}

function selectVehicleDriver(driver) {
setVehicleDriver(driver)
}

const handleUpload = (ids) => {
if (!fileStoreId || fileStoreId.length < 4) {
setFileStoreId(ids);
Expand All @@ -267,6 +324,7 @@ const ActionModal = ({ t, action, tenantId, state, id, closeModal, submitAction,
if (dso) applicationData.dsoId = dso.id;
if (vehicleNo && action === "ACCEPT") applicationData.vehicleId = vehicleNo.id;
if (vehicleNo && action === "DSO_ACCEPT") applicationData.vehicleId = vehicleNo.id;
if (vehicleDriver && action === "DSO_ACCEPT") applicationData.driverId = vehicleDriver.id;
if (vehicle && action === "ASSIGN") applicationData.vehicleType = vehicle.code;
if (data.date) applicationData.possibleServiceDate = new Date(`${data.date}`).getTime();
if (data.desluged) applicationData.completedOn = new Date(data.desluged).getTime();
Expand All @@ -289,7 +347,29 @@ const ActionModal = ({ t, action, tenantId, state, id, closeModal, submitAction,
}
}
if (data.noOfTrips) applicationData.noOfTrips = Number(data.noOfTrips);
if (action === "REASSING") applicationData.vehicleId = null;
if (action === "REASSING") {
applicationData.vehicleId = null
if(applicationData?.workers?.length > 0) {
applicationData.workers = applicationData?.workers?.map(worker => {
return {
...worker,
status:"INACTIVE"
}
})
}
};
//if action is send back we'll inactivate the assigned workers

if (action === "SENDBACK") {
if(applicationData?.workers?.length > 0) {
applicationData.workers = applicationData?.workers?.map(worker => {
return {
...worker,
status:"INACTIVE"
}
})
}
};

if (reassignReason) addCommentToWorkflow(reassignReason, workflow, data);
if (rejectionReason) addCommentToWorkflow(rejectionReason, workflow, data);
Expand All @@ -298,8 +378,44 @@ const ActionModal = ({ t, action, tenantId, state, id, closeModal, submitAction,
if (fstpoRejectionReason && data.comments) workflow.comments = data.comments;
if (fstpoRejectionReason) workflow.fstpoRejectionReason = fstpoRejectionReason?.code;


if(action==="DSO_ACCEPT" || action==="ACCEPT"){
//if driver selected is there in selectedworkers do early return and show toast
if(selectedWorkers?.some?.(worker => worker?.id === selectedDriver?.id)){
setShowToast({ label:"FSM_DRIVER_SW_ERR",error:true });
setTimeout(closeToast, 5000);
return
}
const workersList = [selectedDriver,...tempSelectedWorkers]
// workerList?.filter(worker => worker?.userDetails?.roles?.some(role=> role?.code === "FSM_DRIVER"))
const workerPayload = workersList?.map((worker,idx)=> {
return {
tenantId:worker?.tenantId,
applicationId:applicationData?.id,
individualId:worker?.id,
// workerType:worker?.userDetails?.roles?.some(role=> role?.code === "FSM_DRIVER") ? "DRIVER":"HELPER",
workerType:idx===0 ? "DRIVER":"HELPER",

status:"ACTIVE"
}
})
//resettting the states
setSelectedDriver([])
setSelectedWorkers([])
setDrivers([])
setWorkers([])
refetchWorkers()
submitAction({ fsm: {...applicationData,workers:workerPayload}, workflow });
return
}

submitAction({ fsm: applicationData, workflow });
}

const onRemoveWorkers = (index, workerToRemove) => {
setSelectedWorkers(()=>selectedWorkers?.filter(worker=> worker.individualId!==workerToRemove.individualId))
};

useEffect(() => {
switch (action) {
case "UPDATE":
Expand All @@ -314,6 +430,32 @@ const ActionModal = ({ t, action, tenantId, state, id, closeModal, submitAction,
})
);
case "DSO_ACCEPT":
//TODO: add accept UI
setFormValve(vehicleNo && selectedDriver?.optionsKey ? true : false);
return setConfig(
configAcceptDso({
t,
dsoData,
dso,
vehicle,
vehicleCapacity: applicationData?.vehicleCapacity,
noOfTrips: applicationData?.noOfTrips,
vehicleNo,
vehicleNoList,
selectVehicleNo,
vehicleDriverList,
vehicleDriver,
selectVehicleDriver,
action,
workers,
selectedDriver,
selectedWorkers,
setSelectedDriver,
setSelectedWorkers,
onRemoveWorkers,
drivers,
})
);
case "ACCEPT":
//TODO: add accept UI
setFormValve(vehicleNo ? true : false);
Expand Down
Loading

0 comments on commit b0b1e79

Please sign in to comment.