createorder
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -5,29 +5,12 @@ import {
|
||||
Typography,
|
||||
Stack,
|
||||
Box,
|
||||
// Autocomplete,
|
||||
Button,
|
||||
// Stepper,
|
||||
// Step,
|
||||
// StepLabel,
|
||||
TextField,
|
||||
Autocomplete,
|
||||
CardActions,
|
||||
// CardActions,
|
||||
Chip,
|
||||
// AvatarGroup,
|
||||
// RadioGroup,
|
||||
// Radio
|
||||
Avatar,
|
||||
// List,
|
||||
// ListItem,
|
||||
// IconButton,
|
||||
// ListItemAvatar,
|
||||
// ListItemText,
|
||||
// Menu,
|
||||
// MenuItem,
|
||||
// ListItemIcon,
|
||||
// Link,
|
||||
Divider,
|
||||
Table,
|
||||
TableContainer,
|
||||
@@ -35,7 +18,6 @@ import {
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableBody,
|
||||
// FormLabel,
|
||||
Tooltip,
|
||||
DialogTitle,
|
||||
DialogContent,
|
||||
@@ -50,8 +32,8 @@ import {
|
||||
Select,
|
||||
MenuItem,
|
||||
Switch
|
||||
// LinkOutlined
|
||||
} from '@mui/material';
|
||||
|
||||
import { useNavigate } from 'react-router';
|
||||
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
|
||||
import AccessTimeOutlinedIcon from '@mui/icons-material/AccessTimeOutlined';
|
||||
@@ -138,6 +120,8 @@ function loadScript(src, position, id) {
|
||||
const autocompleteService = { current: null };
|
||||
|
||||
const Createorder1 = () => {
|
||||
const appId = localStorage.getItem('applocationid');
|
||||
|
||||
Geocode.setApiKey(process.env.REACT_APP_GOOGLE_MAPS_API_KEY);
|
||||
|
||||
function GoogleMaps() {
|
||||
@@ -680,8 +664,10 @@ const Createorder1 = () => {
|
||||
|
||||
const [startdate, setStartdate] = useState(dayjs().format('MM-DD-YYYY'));
|
||||
const [enddate, setEnddate] = useState(dayjs().add(1, 'day').format('MM-DD-YYYY'));
|
||||
const [starttime, setStatrttime] = useState(`${dayjs().format('MM-DD-YYYY')} 08:00:00`);
|
||||
const [endtime, setEndtime] = useState(`${dayjs().format('MM-DD-YYYY')} 20:00:00`);
|
||||
// const [starttime, setStatrttime] = useState(`${dayjs().format('MM-DD-YYYY')} 08:00:00`);
|
||||
const [starttime, setStatrttime] = useState();
|
||||
// const [endtime, setEndtime] = useState(`${dayjs().format('MM-DD-YYYY')} 20:00:00`);
|
||||
const [endtime, setEndtime] = useState();
|
||||
|
||||
const [timeslotarr, setTimeslotarr] = useState([]);
|
||||
const [currentsno, setCurrentsno] = useState('');
|
||||
@@ -712,7 +698,8 @@ const Createorder1 = () => {
|
||||
const [clientdetailarr, setClientdetailarr] = useState([]);
|
||||
const [clientdetailbusinessarr, setClientdetailbusinessarr] = useState([]);
|
||||
|
||||
const [admintoken, setAdmintoken] = useState('');
|
||||
// const [admintoken, setAdmintoken] = useState('');
|
||||
const [admintoken, setAdmintoken] = useState();
|
||||
const [tenantlocationlist, setTenantlocationlist] = useState([]);
|
||||
const [tenant, setTenant] = useState({});
|
||||
const [clientinfo, setClientinfo] = useState({});
|
||||
@@ -750,6 +737,20 @@ const Createorder1 = () => {
|
||||
useEffect(() => {
|
||||
fetchTenantPricing();
|
||||
}, []);
|
||||
// const fetchAppPricing = async () => {
|
||||
// try {
|
||||
// const pricingResponse = await axios.get(`${process.env.REACT_APP_URL}/utils/getapppricing/?applocationid=${appId}`);
|
||||
// console.log('pricingResponse', pricingResponse.data.details);
|
||||
// setBasePrice(pricingResponse.data.details.baseprice);
|
||||
// setPricePerKm(pricingResponse.data.details.priceperkm);
|
||||
// setMinKm(pricingResponse.data.details.minkm);
|
||||
// } catch (error) {
|
||||
// console.log('fetchAppPricing error', error);
|
||||
// }
|
||||
// };
|
||||
// useEffect(() => {
|
||||
// fetchAppPricing();
|
||||
// }, []);
|
||||
|
||||
useEffect(() => {
|
||||
console.log('startPoint', startPoint);
|
||||
@@ -872,6 +873,8 @@ const Createorder1 = () => {
|
||||
}
|
||||
});
|
||||
|
||||
// ==================================================== || fetchtenantinfo || ====================================================
|
||||
|
||||
const fetchtenantinfo = async () => {
|
||||
setLoading(true);
|
||||
console.log('tid', tid);
|
||||
@@ -881,8 +884,8 @@ const Createorder1 = () => {
|
||||
console.log('fetchtenantinfo', res);
|
||||
if (res.data.status) {
|
||||
setTenant(res.data.details);
|
||||
|
||||
fetchadmintoken(res.data.details.tenantid, res.data.details.partnerid);
|
||||
// fetchadmintoken(res.data.details.tenantid, res.data.details.partnerid);
|
||||
fetchAppAdminTokens();
|
||||
}
|
||||
setLoading(false);
|
||||
})
|
||||
@@ -896,6 +899,42 @@ const Createorder1 = () => {
|
||||
fetchtenantlocation();
|
||||
}, []);
|
||||
|
||||
// ==================================================== || fetchTiming || ====================================================
|
||||
const fetchTiming = async () => {
|
||||
setLoading(true);
|
||||
console.log('tid', tid);
|
||||
await axios
|
||||
.get(`${process.env.REACT_APP_URL}/utils/getapplocations/?applocationid=${appId}`)
|
||||
.then((res) => {
|
||||
console.log('fetchTiming', res);
|
||||
const { opentime, closetime } = res.data.details[0];
|
||||
if (res.data.status) {
|
||||
setStatrttime(`${dayjs().format('MM-DD-YYYY')} ${opentime}`);
|
||||
setEndtime(`${dayjs().format('MM-DD-YYYY')} ${closetime}`);
|
||||
console.log('starttime', `${dayjs().format('MM-DD-YYYY')} ${opentime}`);
|
||||
console.log('endtime', `${dayjs().format('MM-DD-YYYY')} ${closetime} `);
|
||||
let arr = [];
|
||||
for (
|
||||
let i = `${dayjs().format('MM-DD-YYYY')} ${opentime}`, j = 0;
|
||||
dayjs(`${dayjs().format('MM-DD-YYYY')} ${closetime} `).diff(i, 'm') >= 0;
|
||||
j++, i = dayjs(i).add(30, 'm')
|
||||
) {
|
||||
arr.push(i);
|
||||
}
|
||||
console.log('setTimeslotarr', arr);
|
||||
setTimeslotarr(arr);
|
||||
}
|
||||
setLoading(false);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
setLoading(false);
|
||||
});
|
||||
};
|
||||
useEffect(() => {
|
||||
fetchTiming();
|
||||
}, [starttime, endtime]);
|
||||
|
||||
// const fetchtenantinfolist = async () => {
|
||||
// setLoading(true);
|
||||
// console.log('tid', tid);
|
||||
@@ -948,21 +987,47 @@ const Createorder1 = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const fetchadmintoken = async (tid, pid) => {
|
||||
// // =============================================== || fetchadmintoken (via tid , pid) || ===============================================
|
||||
// const fetchadmintoken = async (tid, pid) => {
|
||||
// setLoading(true);
|
||||
// await axios
|
||||
// .get(`${process.env.REACT_APP_URL}/partners/getadmintoken/?tenantid=${tid}&partnerid=${pid}`)
|
||||
// .then((res) => {
|
||||
// console.log(res);
|
||||
// if (res.data.status) {
|
||||
// setAdmintoken(res.data.details.userfcmtokem);
|
||||
|
||||
// let arr = [];
|
||||
// for (let i = starttime, j = 0; dayjs(endtime).diff(i, 'm') >= 0; j++, i = dayjs(i).add(30, 'm')) {
|
||||
// arr.push(i);
|
||||
// }
|
||||
// console.log(arr);
|
||||
// setTimeslotarr(arr);
|
||||
// }
|
||||
// setLoading(false);
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// console.log(err);
|
||||
// setLoading(false);
|
||||
// });
|
||||
// };
|
||||
// =============================================== || fetchAppAdminTokens (via appId) || ===============================================
|
||||
const fetchAppAdminTokens = async () => {
|
||||
setLoading(true);
|
||||
await axios
|
||||
.get(`${process.env.REACT_APP_URL}/partners/getadmintoken/?tenantid=${tid}&partnerid=${pid}`)
|
||||
.get(`${process.env.REACT_APP_URL}/utils/getapplocationconfig/?applocationid=${appId}`)
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
const userfcmtokemArray = res.data.details.applocationadmins.map((admin) => admin.userfcmtokem);
|
||||
console.log('fetchAppAdminTokens', res);
|
||||
console.log('userfcmtokemArray', userfcmtokemArray);
|
||||
if (res.data.status) {
|
||||
setAdmintoken(res.data.details.userfcmtokem);
|
||||
|
||||
let arr = [];
|
||||
for (let i = starttime, j = 0; dayjs(endtime).diff(i, 'm') >= 0; j++, i = dayjs(i).add(30, 'm')) {
|
||||
arr.push(i);
|
||||
}
|
||||
console.log(arr);
|
||||
setTimeslotarr(arr);
|
||||
setAdmintoken(userfcmtokemArray);
|
||||
// let arr = [];
|
||||
// for (let i = starttime, j = 0; dayjs(endtime).diff(i, 'm') >= 0; j++, i = dayjs(i).add(30, 'm')) {
|
||||
// arr.push(i);
|
||||
// }
|
||||
// console.log('setTimeslotarr', arr);
|
||||
// setTimeslotarr(arr);
|
||||
}
|
||||
setLoading(false);
|
||||
})
|
||||
@@ -972,6 +1037,14 @@ const Createorder1 = () => {
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (starttime && endtime) {
|
||||
fetchAppAdminTokens();
|
||||
}
|
||||
}, [starttime, endtime]);
|
||||
|
||||
// =============================================== || opentoast || ===============================================
|
||||
|
||||
const opentoast = (message) => {
|
||||
enqueueSnackbar(message, {
|
||||
variant: 'error',
|
||||
@@ -989,6 +1062,7 @@ const Createorder1 = () => {
|
||||
setCurrentsno('');
|
||||
}
|
||||
|
||||
// =============================================== || createsubmitobj1 (create orders) || ===============================================
|
||||
const createsubmitobj1 = async () => {
|
||||
let arr = [];
|
||||
let timecheck = false;
|
||||
@@ -1058,7 +1132,8 @@ const Createorder1 = () => {
|
||||
autoHideDuration: 1000
|
||||
});
|
||||
if (admintoken) {
|
||||
notifyadmin(admintoken);
|
||||
// notifyadmin(admintoken);
|
||||
sendnotifications();
|
||||
}
|
||||
|
||||
navigate('/orders');
|
||||
@@ -1078,13 +1153,6 @@ const Createorder1 = () => {
|
||||
console.log(arr);
|
||||
};
|
||||
|
||||
// useEffect(() => {
|
||||
// if (localStorage.getItem('tenantid')) {
|
||||
|
||||
// fetchtenantinfo(localStorage.getItem('tenantid'))
|
||||
// }
|
||||
// }, [clientdetail.tenantname])
|
||||
|
||||
useEffect(() => {
|
||||
console.log('shiftarr');
|
||||
console.log(shiftarr);
|
||||
@@ -1170,21 +1238,59 @@ const Createorder1 = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const notifyadmin = async (id1) => {
|
||||
// ================================================== || notifyadmin || ==================================================
|
||||
// const notifyadmin = async (id1) => {
|
||||
// setLoading(true);
|
||||
// await axios
|
||||
// .post(`${process.env.REACT_APP_URL}/utils/notifyuser`, {
|
||||
// sender: localStorage.getItem('firstname'),
|
||||
// accessid: process.env.REACT_APP_RIDER_ACCESS_ID,
|
||||
// notification: {
|
||||
// priority: 'high',
|
||||
// to: id1,
|
||||
// notification: {
|
||||
// title: 'Nearle Admin',
|
||||
// body: 'Orders has been placed for delivery.Kindly accept and process deliveries',
|
||||
// sound: 'ring'
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// .then((res) => {
|
||||
// console.log(res);
|
||||
// if (res.data.message == 'Success') {
|
||||
// enqueueSnackbar('Notification sent Successfully', {
|
||||
// variant: 'success',
|
||||
// anchorOrigin: { vertical: 'top', horizontal: 'right' },
|
||||
// autoHideDuration: 1000
|
||||
// });
|
||||
// }
|
||||
// setLoading(false);
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// console.log(err);
|
||||
// enqueueSnackbar(err.message, {
|
||||
// variant: 'error',
|
||||
// anchorOrigin: { vertical: 'top', horizontal: 'right' },
|
||||
// autoHideDuration: 1000
|
||||
// });
|
||||
// setLoading(false);
|
||||
// });
|
||||
// };
|
||||
// ================================================== || sendnotifications || ==================================================
|
||||
const sendnotifications = async () => {
|
||||
setLoading(true);
|
||||
await axios
|
||||
.post(`${process.env.REACT_APP_URL}/utils/notifyuser`, {
|
||||
sender: localStorage.getItem('firstname'),
|
||||
accessid: process.env.REACT_APP_RIDER_ACCESS_ID,
|
||||
notification: {
|
||||
.post(`${process.env.REACT_APP_URL}/utils/sendnotifications`, {
|
||||
priority: 'high',
|
||||
to: id1,
|
||||
registration_ids: admintoken,
|
||||
data: {
|
||||
accessid: process.env.REACT_APP_RIDER_ACCESS_ID
|
||||
},
|
||||
notification: {
|
||||
title: 'Nearle Admin',
|
||||
body: 'Orders has been placed for delivery.Kindly accept and process deliveries',
|
||||
title: 'Nearle Merchant',
|
||||
body: 'An Order has been placed successfully,kindly process the same',
|
||||
sound: 'ring'
|
||||
}
|
||||
}
|
||||
})
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
@@ -1423,8 +1529,8 @@ const Createorder1 = () => {
|
||||
{showDistance && (
|
||||
<Grid item xs={12}>
|
||||
<Stack sx={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between' }}>
|
||||
<Chip label={`Distance: ${distance} km`} size="small" variant="light" color="warning" />
|
||||
<Chip label={`Charge: ₹${totalCharge.toFixed(2)}`} size="small" variant="light" color="warning" />
|
||||
<Chip label={`Distance: ${distance} km`} size="small" variant="light" color="primary" />
|
||||
<Chip label={`Charge: ₹${totalCharge.toFixed(2)}`} size="small" variant="light" color="primary" />
|
||||
{/* <Button variant="contained">{`Distance: ${distance} km`}</Button> */}
|
||||
{/* <Button variant="contained">{`Charge: ₹${totalCharge.toFixed(2)}`}</Button> */}
|
||||
</Stack>
|
||||
|
||||
@@ -1648,7 +1648,7 @@ const Orders = () => {
|
||||
try {
|
||||
// await axios.get(`${process.env.REACT_APP_URL}/orders/getordersummary/?tenantid=${tid}&fromdate=${startdate}&todate=${enddate}`)
|
||||
await axios
|
||||
.get(`${process.env.REACT_APP_URL}/orders/getordersummary/?tenantid=${tid}`)
|
||||
.get(`${process.env.REACT_APP_URL}/orders/getordersummary/?applocationid=${tid}`)
|
||||
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
|
||||
@@ -24,7 +24,7 @@ const Details = Loadable(lazy(() => import('pages/nearle/orders/details')));
|
||||
|
||||
const Accountsettings = Loadable(lazy(() => import('pages/nearle/accountsettings')));
|
||||
|
||||
const Createorder = Loadable(lazy(() => import('pages/nearle/orders/createorder')));
|
||||
// const Createorder = Loadable(lazy(() => import('pages/nearle/orders/createorder')));
|
||||
const Createclient = Loadable(lazy(() => import('pages/nearle/clients/createclient')));
|
||||
|
||||
const Createorder1 = Loadable(lazy(() => import('pages/nearle/orders/createorder1')));
|
||||
@@ -71,10 +71,10 @@ const MainRoutes = {
|
||||
path: 'accountsettings',
|
||||
element: <Accountsettings />
|
||||
},
|
||||
{
|
||||
path: 'orders/create1',
|
||||
element: <Createorder />
|
||||
},
|
||||
// {
|
||||
// path: 'orders/create1',
|
||||
// element: <Createorder />
|
||||
// },
|
||||
{
|
||||
path: 'orders/create',
|
||||
element: <Createorder1 />
|
||||
|
||||
Reference in New Issue
Block a user