createorder

This commit is contained in:
joshikannan
2024-04-10 19:50:40 +05:30
parent 77f5295720
commit dc8680d977
6 changed files with 419 additions and 116 deletions

View File

@@ -29,7 +29,9 @@ import {
Switch,
CardHeader,
Card,
OutlinedInput
OutlinedInput,
FormGroup,
FormControlLabel
} from '@mui/material';
import CloseIcon from '@mui/icons-material/Close';
import { Empty } from 'antd';
@@ -387,6 +389,7 @@ const Createorder1 = () => {
const [stafflist, setStafflist] = useState([]);
const [loading2, setLoading2] = useState(false);
const [loading, setLoading] = useState(false);
const [btnLoading, setBtnLoading] = useState(false);
const [shiftarr, setShiftarr] = useState([]);
const [shiftarr1, setShiftarr1] = useState([]);
const [orderarr, setOrderarr] = useState([]);
@@ -433,6 +436,14 @@ const Createorder1 = () => {
const [appLocaLat, setAppLocaLat] = useState();
const [appLocaLng, setAppLocaLng] = useState();
const [appLocaRadius, setAppLocaRadius] = useState();
const [isNumChange1, setIsNumChange1] = useState(0);
const [isNumChange2, setIsNumChange2] = useState(0);
const [showCheck1, setShowCheck1] = useState(0);
const [showCheck2, setShowCheck2] = useState(0);
const [pickNum, setPickNum] = useState();
const [dropNum, setdropNum] = useState();
const [numErr1, setNumErr1] = useState(false);
const [numErr2, setNumErr2] = useState(false);
const [isSms, setIsSms] = useState(0);
useEffect(() => {
@@ -801,13 +812,13 @@ const Createorder1 = () => {
cancellled: '',
categoryid: +tenant.categoryid,
configid: +localStorage.getItem('configid'),
customerid: +pickCust.customerid || 0,
customerid: isNumChange1 == 0 ? +pickCust.customerid || 0 : 0,
deliveryaddress: dropCust.address || '',
deliverycharge: +totalCharge.toFixed(2) || 0,
deliverycity: dropCust.city || '',
deliverycontactno: dropCust.contactno || '',
deliverycustomer: dropCust.firstname || '',
deliveryid: dropCust.customerid || 0,
deliveryid: isNumChange2 == 0 ? +dropCust.customerid || 0 : 0,
deliverylandmark: dropCust.landmark || '',
deliverylat: dropCust.latitude.toString(),
deliverylocation: dropCust.suburb || '',
@@ -859,7 +870,7 @@ const Createorder1 = () => {
configid: parseInt(localStorage.getItem('configid')),
contactno: pickCust.contactno || '',
customertoken: '',
customerid: pickCust.customerid || 0,
customerid: isNumChange1 == 0 ? pickCust.customerid || 0 : 0,
devicetype: '',
deviceid: '',
dialcode: '+91',
@@ -885,7 +896,7 @@ const Createorder1 = () => {
configid: parseInt(localStorage.getItem('configid')),
contactno: dropCust.contactno || '',
customertoken: '',
customerid: dropCust.customerid || 0,
customerid: isNumChange2 == 0 ? dropCust.customerid || 0 : 0,
devicetype: '',
deviceid: '',
dialcode: '+91',
@@ -906,33 +917,37 @@ const Createorder1 = () => {
};
console.log('createsubmitobj2', arr);
if (!pickCust.firstname) {
opentoast('Enter Pickup Contact Name ', 'warning');
opentoast('Enter Pickup Contact Name ', 'warning', 2000);
} else if (!pickCust.contactno) {
opentoast('Enter Pickup Contact Number ', 'warning');
opentoast('Enter Pickup Contact Number ', 'warning', 2000);
} else if (pickCust.contactno.length != 10) {
opentoast('Check Pickup Contact Number ', 'error', 2000);
} else if (!pickCust.suburb) {
opentoast('Enter Pickup Location ', 'warning');
opentoast('Enter Pickup Location ', 'warning', 2000);
} else if (!pickCust.city) {
opentoast('Enter Pickup City ', 'warning');
opentoast('Enter Pickup City ', 'warning', 2000);
} else if (!pickCust.postcode) {
opentoast('Enter Pickup Postcode ', 'warning');
opentoast('Enter Pickup Postcode ', 'warning', 2000);
} else if (!pickCust.landmark) {
opentoast('Enter Pickup Landmark ', 'warning');
opentoast('Enter Pickup Landmark ', 'warning', 2000);
} else if (!dropCust.firstname) {
opentoast('Enter Drop Contact Name ', 'warning');
opentoast('Enter Drop Contact Name ', 'warning', 2000);
} else if (!dropCust.contactno) {
opentoast('Enter Drop Contact Number', 'warning');
opentoast('Enter Drop Contact Number', 'warning', 2000);
} else if (dropCust.contactno.length !== 10) {
opentoast('Check Drop Contact Number ', 'error', 2000);
} else if (!dropCust.suburb) {
opentoast('Enter Drop Suburb ', 'warning');
opentoast('Enter Drop Suburb ', 'warning', 2000);
} else if (!dropCust.city) {
opentoast('Enter Drop City ', 'warning');
opentoast('Enter Drop City ', 'warning', 2000);
} else if (!dropCust.postcode) {
opentoast('Enter Drop postcode ', 'warning');
opentoast('Enter Drop postcode ', 'warning', 2000);
} else if (!dropCust.landmark) {
opentoast('Enter Drop Landmark ', 'warning');
opentoast('Enter Drop Landmark ', 'warning', 2000);
} else if (!selectedtime) {
opentoast('Choose deliverytime ', 'warning');
opentoast('Choose deliverytime ', 'warning', 2000);
} else if (!setSubCatId) {
opentoast('Choose SubCategory ', 'warning');
opentoast('Choose SubCategory ', 'warning', 2000);
} else {
try {
const createRes = await axios.post(`${process.env.REACT_APP_URL2}/orders/createorder`, arr);
@@ -1392,7 +1407,7 @@ const Createorder1 = () => {
setIsCustomerOpen(true);
setpickordrop(1);
setPickCust({});
setAddId1(1);
setInputValue2('');
setSearchCustList('');
}
@@ -1464,32 +1479,6 @@ const Createorder1 = () => {
<Grid item xs={12} sx={{}}>
<Grid container spacing={4}>
{/* ====================================== ||Contact Number(pick) || ====================================== */}
<Grid item xs={6}>
<TextField
disabled={!isLocation}
fullWidth
type="number"
InputProps={{
inputProps: {
maxLength: 10
},
startAdornment: (
<IconButton>
<FaPhoneAlt />
</IconButton>
)
}}
variant="outlined"
label="Contact Number"
value={pickCust.contactno}
onChange={(e) => {
if (e.target.value.length <= 10) {
setPickCust({ ...pickCust, contactno: e.target.value });
}
}}
/>
</Grid>
{/* ====================================== ||Contact Name (pick) || ====================================== */}
<Grid item xs={6}>
<TextField
@@ -1511,9 +1500,44 @@ const Createorder1 = () => {
}}
/>
</Grid>
{/* ====================================== ||Contact Number(pick) || ====================================== */}
<Grid item xs={6}>
<TextField
error={numErr1}
disabled={!isLocation}
fullWidth
type="number"
InputProps={{
inputProps: {
maxLength: 10
},
startAdornment: (
<IconButton>
<FaPhoneAlt color={numErr1 && 'red'} />
</IconButton>
)
}}
variant="outlined"
label="Contact Number"
value={pickCust.contactno}
onChange={(e) => {
if (e.target.value.length <= 10) {
setPickCust({ ...pickCust, contactno: e.target.value });
}
if (pickNum == e.target.value) {
setShowCheck1(0);
} else {
setShowCheck1(1);
}
if (e.target.value.length < 10) {
setNumErr1(true);
} else {
setNumErr1(false);
}
}}
/>
</Grid>
{/* ====================================== || Address (pick) || ====================================== */}
<Grid item xs={12}>
<Stack spacing={1.25} sx={{ mt: 0 }}>
{addId1 == 0 ? (
@@ -1691,6 +1715,24 @@ const Createorder1 = () => {
}}
/>
</Grid>
{/* ====================================== ||Checkbox save for later (pick) || ====================================== */}
{showCheck1 == 1 && (
<Grid item xs={12} sx={{ display: 'flex', justifyContent: 'end' }}>
<FormGroup>
<FormControlLabel
control={
<Checkbox
checked={isNumChange1 === 1}
onChange={(e) => {
setIsNumChange1(e.target.checked ? 1 : 0);
}}
/>
}
label="Save For Later"
/>
</FormGroup>
</Grid>
)}
</Grid>
</Grid>
{/* <Stack
@@ -1755,7 +1797,7 @@ const Createorder1 = () => {
} else {
setIsCustomerOpen(true);
setpickordrop(2);
setAddId2(1);
setInputValue3('');
setSearchCustList('');
}
@@ -1831,29 +1873,6 @@ const Createorder1 = () => {
<Grid item xs={12}>
<Grid container spacing={4}>
{/* ====================================== ||Contact Number (drop) || ====================================== */}
<Grid item xs={6}>
<TextField
disabled={!isLocation}
fullWidth
type="number"
variant="outlined"
label="Contact Number"
InputProps={{
startAdornment: (
<IconButton>
<FaPhoneAlt />
</IconButton>
)
}}
value={dropCust.contactno}
onChange={(e) => {
if (e.target.value.length <= 10) {
setDropCust({ ...dropCust, contactno: e.target.value });
}
}}
/>
</Grid>
{/* ====================================== ||Contact Name (drop) || ====================================== */}
<Grid item xs={6}>
<TextField
@@ -1875,7 +1894,40 @@ const Createorder1 = () => {
}}
/>
</Grid>
{/* ====================================== ||Contact Number (drop) || ====================================== */}
<Grid item xs={6}>
<TextField
disabled={!isLocation}
error={numErr2}
fullWidth
type="number"
variant="outlined"
label="Contact Number"
InputProps={{
startAdornment: (
<IconButton>
<FaPhoneAlt color={numErr2 && 'red'} />
</IconButton>
)
}}
value={dropCust.contactno}
onChange={(e) => {
if (e.target.value.length <= 10) {
setDropCust({ ...dropCust, contactno: e.target.value });
}
if (dropNum == e.target.value) {
setShowCheck2(0);
} else {
setShowCheck2(1);
}
if (e.target.value.length < 10) {
setNumErr2(true);
} else {
setNumErr2(false);
}
}}
/>
</Grid>
<Grid item xs={12}>
<Stack spacing={1.25} sx={{ mt: 0 }}>
{addId2 == 0 ? (
@@ -2054,6 +2106,24 @@ const Createorder1 = () => {
}}
/>
</Grid>
{/* ====================================== ||Checkbox save for later (drop) || ====================================== */}
{showCheck2 == 1 && (
<Grid item xs={12} sx={{ display: 'flex', justifyContent: 'end' }}>
<FormGroup>
<FormControlLabel
control={
<Checkbox
checked={isNumChange2 === 1}
onChange={(e) => {
setIsNumChange2(e.target.checked ? 1 : 0);
}}
/>
}
label="Save For Later"
/>
</FormGroup>
</Grid>
)}
</Grid>
</Grid>
{/* <Stack
@@ -2077,7 +2147,7 @@ const Createorder1 = () => {
</Grid>
{/* ================================================= || Time || ================================================= */}
<Grid item xs={12} sm={6}>
<MainCard sx={{ mt: 2 }}>
<MainCard sx={{ mt: 2, height: '390px' }}>
<Grid container>
<Grid item xs={12}>
<Typography variant="h5">Date</Typography>
@@ -2185,46 +2255,36 @@ const Createorder1 = () => {
</MainCard>
</Grid>
<Grid item xs={12} sm={6} sx={{}}>
<MainCard sx={{ mt: 2, height: 330 }}>
<MainCard sx={{ mt: 2, height: '390px' }}>
{showDistance && (
<Stack sx={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', mb: 3 }}>
<Stack spacing={1.5}>
<Typography variant="h5">Distance</Typography>
<Chip label={`Distance: ${distance} km`} size="medium" variant="contained" color="primary" />
</Stack>
<Stack spacing={1.5}>
<Typography variant="h5">Charges</Typography>
<Chip label={`Charge: ₹${totalCharge.toFixed(2)}`} size="medium" variant="contained" color="primary" />
</Stack>
</Stack>
)}
<Stack direction={'row'} justifyContent={'space-between'}>
<Typography variant="h5">SMS Delivery</Typography>
<Switch
checked={isSms === 1}
onChange={(e) => {
setIsSms(e.target.checked ? 1 : 0);
<Stack direction={'column'} justifyContent={'space-between'} sx={{ mb: 2 }}>
<Typography variant="h5">Category</Typography>
<Autocomplete
disablePortal
id="combo-box-demo"
options={subCat}
getOptionLabel={(option) => `${option.subcategoryname}` || ''}
sx={{ my: 2, zIndex: '100' }}
fullWidth
renderInput={(params) => <TextField {...params} label={subCatName == '' ? tenant.subcategoryname : subCatName} />}
onChange={(event, value, reason) => {
if (value) {
console.log(value);
setSubCatName(value.subcategoryname);
setSubCatId(value.subcategoryid);
}
}}
/>
</Stack>
<Typography variant="h5">Category</Typography>
<Autocomplete
disablePortal
id="combo-box-demo"
options={subCat}
getOptionLabel={(option) => `${option.subcategoryname}` || ''}
sx={{ my: 2, zIndex: '100' }}
fullWidth
renderInput={(params) => <TextField {...params} label={subCatName == '' ? tenant.subcategoryname : subCatName} />}
onChange={(event, value, reason) => {
if (value) {
console.log(value);
setSubCatName(value.subcategoryname);
setSubCatId(value.subcategoryid);
}
}}
/>
<Typography variant="h5">Weight</Typography>
<Stack direction={'row'} justifyContent={'space-evenly'} sx={{ border: '1px solid #eee', my: 2, py: 2 }}>
<Chip
@@ -2258,6 +2318,15 @@ const Createorder1 = () => {
}}
/>
</Stack>
<Stack direction={'row'} justifyContent={'space-between'} sx={{ mt: 4 }}>
<Typography variant="h5">SMS Delivery</Typography>
<Switch
checked={isSms === 1}
onChange={(e) => {
setIsSms(e.target.checked ? 1 : 0);
}}
/>
</Stack>
</MainCard>
</Grid>
</Grid>
@@ -2284,24 +2353,26 @@ const Createorder1 = () => {
</Grid>
<Stack direction="row" justifyContent={'end'} sx={{ mt: 2, width: '100%' }}>
<Button
size="medium"
disabled={!showDistance}
variant="contained"
sx={{
'&:hover': {
bgcolor: 'white',
color: theme.palette.primary.main,
border: `1px solid ${theme.palette.primary.main}`
}
}}
variant="outlined"
onClick={() => {
setLoading(true);
setBtnLoading(true);
createsubmitobj2();
setTimeout(() => {
setLoading(false);
setBtnLoading(false);
}, 1000);
}}
sx={{
'&:hover': {
transform: 'scale(1.05)',
transition: 'transform 0.3s ease'
}
}}
>
Create
{btnLoading ? <CircularProgress color="primary" size={20} thickness={10} /> : 'Create'}
</Button>
</Stack>
</Grid>
@@ -2429,13 +2500,16 @@ const Createorder1 = () => {
setIsCustomerOpen(false);
if (pickordrop === 1) {
console.log('PickupClient', address);
setAddId1(1);
setStartPoint({ latitude: address.latitude, longitude: address.longitude });
setPickCust(address);
setPickNum(address.contactno);
} else {
console.log('DropClient', address);
setDropCust(address);
setAddId2(1);
setEndPoint({ latitude: address.latitude, longitude: address.longitude });
setDropCust(address);
setdropNum(address.contactno);
}
}}
disabled={pickCust.customerid === address.customerid}