principal distributor create with address and salescoordinator attendance system create

This commit is contained in:
Sibunnayak 2024-07-19 12:22:45 +05:30
parent 72a3b40cfd
commit 0146a7a3d2
12 changed files with 532 additions and 471 deletions

View File

@ -38,6 +38,8 @@
"@coreui/utils": "^1.3.1",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@headlessui/react": "^2.1.2",
"@heroicons/react": "^2.1.5",
"@material-ui/core": "^4.12.4",
"@material-ui/data-grid": "^4.0.0-alpha.37",
"@mui/icons-material": "^5.14.14",

View File

@ -83,13 +83,13 @@ const _nav = [
to: "/salescoordinators",
group: "SalesCoOrdinator",
},
// {
// component: CNavItem,
// name: "Attendance",
// icon: <CIcon icon={cilUser} customClassName="nav-icon" />,
// to: "/attendance/today",
// group: "AttendanceSalesCoOrdinator",
// },
{
component: CNavItem,
name: "Attendance",
icon: <CIcon icon={cilUser} customClassName="nav-icon" />,
to: "/attendance/today",
group: "AttendanceSalesCoOrdinator",
},
// {
// component: CNavGroup,
// name: "Orders",

View File

@ -31,7 +31,7 @@ const AppSidebar = () => {
const [userdata, setUserData] = useState(null);
const token = isAutheticated();
console.log("userDatt", userdata);
// console.log("userDatt", userdata);
useEffect(() => {
const getUser = async () => {

View File

@ -15,8 +15,8 @@ import { cibGmail } from "@coreui/icons";
import { createRoot } from "react-dom/client";
const setupAxios = () => {
axios.defaults.baseURL = "http://localhost:5000";
// axios.defaults.baseURL = "https://cheminova-api-2.onrender.com";
// axios.defaults.baseURL = "http://localhost:5000";
axios.defaults.baseURL = "https://cheminova-api-2.onrender.com";
axios.defaults.headers = {
"Cache-Control": "no-cache,no-store",

View File

@ -1,101 +1,87 @@
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import {
TextField,
Button,
Card,
FormControl,
Grid,
Typography,
FormHelperText,
OutlinedInput,
Box,
Autocomplete,
CircularProgress,
} from "@mui/material";
import { useNavigate } from "react-router-dom";
import toast from "react-hot-toast";
import axios from "axios";
import { isAutheticated } from "src/auth";
const styles = {
formStyle: {
fontWeight: "700",
fontSize: "12px",
fontFamily: "inter",
marginBottom: "3px",
marginLeft: "0",
},
topRightButton: {
position: "absolute",
top: "10px",
right: "10px",
},
};
import { City, State } from "country-state-city";
const AddPrincipalDistributor = () => {
const navigate = useNavigate();
const token = isAutheticated();
const [user, setUser] = useState({
name: "",
email: "",
password: "",
phone: "",
});
const [id, setUserId] = useState("");
const token = isAutheticated();
const [loading, setLoading] = useState(false);
const [data, setData] = useState({
street: "",
city: "",
state: "",
postalCode: "",
country: "",
company_name: "",
gst_number: "",
country: "India",
tradeName: "",
gstNumber: "",
panNumber: "",
});
const handleChange = (e) => {
setData((prev) => ({ ...prev, [e.target.name]: e.target.value }));
};
const [loading, setLoading] = useState(false);
const [stateOptions, setStateOptions] = useState([]);
const [cityOptions, setCityOptions] = useState([]);
const [selectedState, setSelectedState] = useState(null);
const [selectedCity, setSelectedCity] = useState(null);
const handleInputChanges = (e) => {
useEffect(() => {
const fetchStates = async () => {
const states = State.getStatesOfCountry("IN").map((state) => ({
label: state.name,
value: state.isoCode,
}));
setStateOptions(states);
};
fetchStates();
}, []);
useEffect(() => {
const fetchCities = async () => {
if (selectedState) {
const cities = City.getCitiesOfState("IN", selectedState.value).map(
(city) => ({
label: city.name,
value: city.name,
})
);
setCityOptions(cities);
}
};
fetchCities();
}, [selectedState]);
const handleInputChange = (e) => {
setUser({ ...user, [e.target.name]: e.target.value });
};
const handleAddressSubmit = (e) => {
e.preventDefault();
if (
data.street === "" ||
data.city === "" ||
data.state === "" ||
data.postalCode === "" ||
data.country === ""
) {
toast.error("Please fill all mandatory fields.");
return;
}
setLoading(true);
axios
.post(
`/api/shipping/address/admin/new/${id}`,
{ ...data },
{
headers: {
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
}
)
.then((res) => {
setLoading(false);
navigate("/principal-distributor");
toast.success(res.data.message ? res.data.message : "Address Added!");
})
.catch((error) => {
setLoading(false);
toast.error(
error.response.data.message
? error.response.data.message
: "Something went wrong!"
);
});
const handleDataChange = (e) => {
setData({ ...data, [e.target.name]: e.target.value });
};
const handleStateChange = (event, newValue) => {
setSelectedState(newValue);
};
const handleCityChange = (event, newValue) => {
setSelectedCity(newValue);
};
const generatePassword = (name, email) => {
@ -119,25 +105,51 @@ const AddPrincipalDistributor = () => {
const handleFormSubmit = async (e) => {
e.preventDefault();
try {
if (!user.name || !user.email || !user.phone) {
if (
!user.name ||
!user.email ||
!user.phone ||
!selectedState ||
!selectedCity ||
!data.street ||
!data.postalCode
) {
throw new Error("Fill all fields!");
}
setLoading(true);
const generatedPassword = generatePassword(user.name, user.email);
setUser({ ...user, password: generatedPassword });
const response = await axios.post("/api/v1/user/register", {
const userResponse = await axios.post("/api/v1/user/register", {
...user,
password: generatedPassword,
});
if (response.status === 201) {
toast.success("User Added Successfully");
// console.log(response.data);
setUserId(response.data.userId);
if (userResponse.status === 201) {
const userId = userResponse.data.userId;
const addressResponse = await axios.post(
`/api/shipping/address/admin/new/${userId}`,
{
...data,
state: selectedState.label, // Send selected state label
city: selectedCity.label, // Send selected city label
},
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
setLoading(false);
if (addressResponse.status === 201) {
toast.success("Principal Distributor and Address Added Successfully");
navigate("/principal-distributor");
}
}
} catch (error) {
console.log(error.response.data.message);
toast.error(error.response.data.message);
setLoading(false);
console.error("Error adding principal distributor and address:", error);
toast.error(error.response?.data?.message || "Something went wrong!");
}
};
@ -154,204 +166,196 @@ const AddPrincipalDistributor = () => {
variant="outlined"
color="secondary"
onClick={handleCancel}
sx={styles.topRightButton}
sx={{ position: "absolute", top: "10px", right: "10px" }}
>
Cancel
</Button>
<form style={{ marginBottom: "2rem" }} onSubmit={handleFormSubmit}>
<Typography variant="h5" sx={{ mb: 3 }}>
Add Principal Distributor
</Typography>
<form onSubmit={handleFormSubmit}>
<Typography variant="h6" sx={{ mb: 2 }}>
Basic Information
</Typography>
<Grid container spacing={2} sx={{ mb: 2 }}>
<Grid item xs={12} sm={4}>
<TextField
id="name"
required
type="text"
sx={{ marginBottom: "2rem", width: "50%" }}
fullWidth
name="name"
value={user.name}
label="Name"
variant="outlined"
onChange={handleInputChanges}
onChange={handleInputChange}
/>
<br />
</Grid>
<Grid item xs={12} sm={4}>
<TextField
id="email"
type="email"
sx={{ mb: "2rem", width: "50%" }}
required
type="email"
fullWidth
name="email"
value={user.email}
label="Email"
variant="outlined"
onChange={handleInputChanges}
onChange={handleInputChange}
/>
<br />
</Grid>
<Grid item xs={12} sm={4}>
<TextField
id="phone"
type="tel"
sx={{ mb: "2rem", width: "50%" }}
required
type="text"
fullWidth
name="phone"
value={user.phone}
label="Mobile Number"
label="Phone Number"
variant="outlined"
onChange={handleInputChanges}
onChange={handleInputChange}
/>
<br />
<Button variant="contained" disabled={id?.length > 0} type="submit">
Add Principal Distributor
</Button>
<br />
</form>
</Grid>
</Grid>
<form onSubmit={handleAddressSubmit}>
<Grid container spacing={2}>
<Grid item xs={12}>
<FormControl variant="outlined" fullWidth>
<FormHelperText
id="outlined-weight-helper-text"
sx={styles.formStyle}
>
STREET ADDRESS*
</FormHelperText>
<OutlinedInput
size="small"
id="outlined-adornment-weight"
placeholder="Street Address"
aria-describedby="outlined-weight-helper-text"
name="street"
<Typography variant="h6" sx={{ mb: 2 }}>
Business Details
</Typography>
<Grid container spacing={2} sx={{ mb: 2 }}>
<Grid item xs={12} sm={4}>
<TextField
id="panNumber"
required
type="text"
onChange={handleChange}
fullWidth
name="panNumber"
value={data.panNumber}
label="PAN Number"
variant="outlined"
onChange={handleDataChange}
/>
</FormControl>
</Grid>
<Grid item xs={12}>
<FormControl variant="outlined" fullWidth>
<FormHelperText
id="outlined-weight-helper-text"
sx={styles.formStyle}
>
COUNTRY*
</FormHelperText>
<OutlinedInput
size="small"
id="outlined-adornment-weight"
placeholder="Country"
aria-describedby="outlined-weight-helper-text"
<Grid item xs={12} sm={4}>
<TextField
id="tradeName"
// required
type="text"
fullWidth
name="tradeName"
value={data.tradeName}
label="Trade Name"
variant="outlined"
onChange={handleDataChange}
/>
</Grid>
<Grid item xs={12} sm={4}>
<TextField
id="gstNumber"
// required
type="text"
fullWidth
name="gstNumber"
value={data.gstNumber}
label="GST Number"
variant="outlined"
onChange={handleDataChange}
/>
</Grid>
<Typography variant="h6" sx={{ mb: 2 }}>
Address
</Typography>
<Grid item xs={12} sm={4}>
<TextField
id="country"
required
type="text"
fullWidth
name="country"
required
type="text"
onChange={handleChange}
value={data.country}
label="Country"
variant="outlined"
disabled
/>
</FormControl>
</Grid>
<Grid item xs={12}>
<FormControl fullWidth variant="outlined">
<FormHelperText
id="outlined-weight-helper-text"
sx={styles.formStyle}
>
TOWN CITY*
</FormHelperText>
<OutlinedInput
size="small"
id="outlined-adornment-weight"
placeholder="Town City"
aria-describedby="outlined-weight-helper-text"
name="city"
required
type="text"
onChange={handleChange}
<Grid item xs={12} sm={4}>
<Autocomplete
id="state"
options={stateOptions}
getOptionLabel={(option) => option.label}
value={selectedState}
onChange={handleStateChange}
renderInput={(params) => (
<TextField
{...params}
fullWidth
label="State"
variant="outlined"
error={!selectedState}
helperText={!selectedState ? "Select a state" : null}
/>
)}
/>
</Grid>
<Grid item xs={12} sm={4}>
<Autocomplete
id="city"
options={cityOptions}
getOptionLabel={(option) => option.label}
value={selectedCity}
onChange={handleCityChange}
renderInput={(params) => (
<TextField
{...params}
fullWidth
label="City"
variant="outlined"
error={!selectedCity}
helperText={!selectedCity ? "Select a city" : null}
/>
)}
/>
</FormControl>
</Grid>
<Grid item xs={6}>
<FormControl variant="outlined" fullWidth>
<FormHelperText
id="outlined-weight-helper-text"
sx={styles.formStyle}
>
STATE*
</FormHelperText>
<OutlinedInput
size="small"
id="outlined-adornment-weight"
placeholder="State"
aria-describedby="outlined-weight-helper-text"
name="state"
<TextField
id="street"
required
type="text"
onChange={handleChange}
fullWidth
name="street"
value={data.street}
label="Street"
variant="outlined"
onChange={handleDataChange}
/>
</FormControl>
</Grid>
<Grid item xs={6}>
<FormControl variant="outlined" fullWidth>
<FormHelperText
id="outlined-weight-helper-text"
sx={styles.formStyle}
>
ZIP CODE*
</FormHelperText>
<OutlinedInput
size="small"
id="outlined-adornment-weight"
placeholder="Zip Code"
aria-describedby="outlined-weight-helper-text"
<TextField
id="postalCode"
required
type="text"
fullWidth
name="postalCode"
required
type="number"
onChange={handleChange}
value={data.postalCode}
label="Postal Code"
variant="outlined"
onChange={handleDataChange}
/>
</FormControl>
</Grid>
<Grid item xs={12}>
<FormControl variant="outlined" fullWidth>
<FormHelperText
id="outlined-weight-helper-text"
sx={styles.formStyle}
>
Company Name
</FormHelperText>
<OutlinedInput
size="small"
id="outlined-adornment-weight"
placeholder="Company name"
aria-describedby="outlined-weight-helper-text"
name="company_name"
type="text"
onChange={handleChange}
/>
</FormControl>
</Grid>
<Grid item xs={12}>
<FormControl variant="outlined" fullWidth>
<FormHelperText
id="outlined-weight-helper-text"
sx={styles.formStyle}
>
GST Number
</FormHelperText>
<OutlinedInput
size="small"
id="outlined-adornment-weight"
placeholder="GST Number"
aria-describedby="outlined-weight-helper-text"
name="gst_number"
type="text"
onChange={handleChange}
/>
</FormControl>
</Grid>
<Grid item xs={12}>
<Button
variant="contained"
disabled={!id?.length > 0}
type="submit"
disabled={loading}
variant="contained"
color="primary"
>
Submit
{loading ? (
<CircularProgress size={24} />
) : (
"Create Principal Distributor"
)}
</Button>
</Grid>
</Grid>
</form>
</Card>
</div>

View File

@ -192,8 +192,9 @@ const principalDistributor = () => {
style={{ background: "rgb(140, 213, 213)" }}
>
<tr>
<th>Principal Distributor Name</th>
<th>Unique Id </th>
<th>Name</th>
<th>Email</th>
{/* <th>Profile Image</th> */}
<th>Date Registered</th>
@ -220,9 +221,9 @@ const principalDistributor = () => {
showData.map((user, i) => {
return (
<tr key={i}>
<td>{user.uniqueId}</td>
<td className="text-start">{user.name}</td>
<td>{user._id}</td>
<td>{user.email}</td>
<td className="text-start">
{new Date(user.createdAt).toLocaleString(
"en-IN",

View File

@ -137,18 +137,35 @@ const SinglePrincipalDistributorAllDetails = () => {
</div>
</div>
<div className="card" style={{ padding: "1rem" }}>
<h5 style={{ fontWeight: "bold" }}>&bull; Customer Profile </h5>
<h5 style={{ fontWeight: "bold" }}>&bull; Principal Distributor Profile </h5>
<div style={{ marginLeft: "1rem", marginTop: "1rem" }}>
<Typography style={{ fontWeight: "bold" }}>
Customer Name:<b> {user?.name}</b>
<Typography style={{ fontWeight: "bold", fontSize: "1.2rem" }}>
Principal Distributor ID:
<Typography component="span" style={{ fontWeight: "normal", fontSize: "1.2rem",marginLeft: "0.5rem" }}>
{user?.uniqueId}
</Typography>
<Typography style={{ fontWeight: "bold" }}>
Customer ID:<b style={{ marginLeft: "1.5rem" }}> {user?._id}</b>
</Typography>
<Typography style={{ fontWeight: "bold" }}>
<Typography style={{ fontWeight: "bold", fontSize: "1.2rem" }}>
Name:
<Typography component="span" style={{ fontWeight: "normal", fontSize: "1.2rem",marginLeft: "0.5rem"}}>
{user?.name}
</Typography>
</Typography>
<Typography style={{ fontWeight: "bold", fontSize: "1.2rem" }}>
Mail:
<Typography component="span" style={{ fontWeight: "normal", fontSize: "1.2rem" ,marginLeft: "0.5rem"}}>
{user?.email}
</Typography>
</Typography>
<Typography style={{ fontWeight: "bold", fontSize: "1.2rem" }}>
Mobile Number:
<Typography component="span" style={{ fontWeight: "normal", fontSize: "1.2rem" ,marginLeft: "0.5rem"}}>
{user?.phone}
</Typography>
</Typography>
<Typography style={{ fontWeight: "bold", fontSize: "1.2rem" }}>
Date Registered:
<b>
{" "}
<Typography component="span" style={{ fontWeight: "normal", fontSize: "1.2rem" ,marginLeft: "0.5rem"}}>
{new Date(user?.createdAt).toLocaleString("en-IN", {
weekday: "short",
month: "short",
@ -158,11 +175,11 @@ const SinglePrincipalDistributorAllDetails = () => {
minute: "numeric",
hour12: true,
})}
</b>
</Typography>
<Typography style={{ fontWeight: "bold" }}>
</Typography>
<Typography style={{ fontWeight: "bold", fontSize: "1.2rem" }}>
Last Purchase:
<b style={{ marginLeft: "1.5rem" }}>
<Typography component="span" style={{ fontWeight: "normal", fontSize: "1.2rem", marginLeft: "1.5rem" }}>
{userOrder?.length > 0
? new Date(userOrder[0]?.createdAt).toLocaleString("en-IN", {
weekday: "short",
@ -176,9 +193,10 @@ const SinglePrincipalDistributorAllDetails = () => {
: userOrder
? "No Purchase"
: "Loading"}
</b>
</Typography>
</Typography>
</div>
<div style={{ marginTop: "2rem" }}>
<h5 style={{ fontWeight: "bold", marginBottom: "1rem" }}>
&bull; Addresses{" "}
@ -216,10 +234,10 @@ const SinglePrincipalDistributorAllDetails = () => {
<td className="text-start">{i + 1}</td>
<td style={{ maxWidth: "400px" }}>
<strong>
{address?.first_Name} {address?.last_name},
{address?.first_Name} {address?.last_name}
{address.company_name
? `${address.company_name},`
: ""}
: "No Company_Name "}
{address.gst_number ? `${address.gst_number},` : ""}
{address?.phone_Number},{address?.street},
{address?.city},{address?.state},{address?.country},

View File

@ -3,7 +3,7 @@ import { CForm, CCol, CFormLabel, CContainer, CRow, CCardGroup, CCard, CCardBody
import { useState, useEffect } from 'react'
import axios from 'axios'
import { useNavigate } from 'react-router-dom'
import { Navigate, useNavigate } from 'react-router-dom'
import { isAutheticated } from 'src/auth'
const EditProfile = () => {
@ -115,7 +115,7 @@ const EditProfile = () => {
}
}
const handleCancle = () => {
history.push('/dashboard')
Navigate("/dashboard");
}
useEffect(() => {

View File

@ -81,6 +81,11 @@ const AddSalesCoOrdinator = () => {
}
};
// Function to handle cancel button click
const handleCancel = () => {
navigate("/salescoordinators"); // Navigate to '/salescoordinators'
};
return (
<div className="main-content">
<div className="my-3 page-content">
@ -89,6 +94,9 @@ const AddSalesCoOrdinator = () => {
<div className="col-12">
<div className="page-title-box d-flex align-items-center justify-content-between">
<h4 className="mb-3">Add Sales Coordinator</h4>
<Button variant="danger" onClick={handleCancel}>
Cancel
</Button>
</div>
</div>
</div>

View File

@ -208,6 +208,7 @@ const SalesCoOrdinator = () => {
style={{ background: "#ecdddd" }}
>
<tr>
<th>Unique Id </th>
<th className="text-start">Name</th>
<th className="text-start">Mobile No.</th>
<th className="text-start">Email</th>
@ -228,6 +229,9 @@ const SalesCoOrdinator = () => {
salescoordinatorsData?.map((salescoordinator, i) => {
return (
<tr key={i}>
<td className="text-start">
{salescoordinator?.uniqueId}
</td>
<td className="text-start">
{salescoordinator?.name}
</td>

View File

@ -8,6 +8,7 @@ const WidgetsDropdown = lazy(() => import("../widgets/WidgetsDropdown.js"));
const Dashboard = () => {
//1 st
const [users, setUsers] = useState([]);
const [salescoordinator, setSalescoordinator] = useState([]);
const token = isAutheticated();
const getAllUsers = async () => {
@ -19,39 +20,48 @@ const Dashboard = () => {
// console.log(res.data)
setUsers(res.data.users);
};
//2nd
const [category, setCategory] = useState([]);
const getAllCategory = async () => {
let res = await axios.get(`/api/category/getCategories`, {
const getAllsalescoordinator = async () => {
let res = await axios.get(`/api/salescoordinator/getAll/`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
// console.log(res.data);
setCategory(res?.data?.categories);
};
//3rd
const [product, setProduct] = useState([]);
const getAllProduct = async () => {
let res = await axios.get(`/api/product/getAll/user/`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
// console.log(res.data);
setProduct(res?.data?.product);
};
// 3rd
const [Requests, setRequests] = useState([]);
const getAllRequests = async () => {
let res = await axios.get(`/api/contact/request/getAll/`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
// console.log(res.data);
setRequests(res.data.contactRequest);
// console.log(res.data)
setSalescoordinator(res.data.total_data);
};
// //2nd
// const [category, setCategory] = useState([]);
// const getAllCategory = async () => {
// let res = await axios.get(`/api/category/getCategories`, {
// headers: {
// Authorization: `Bearer ${token}`,
// },
// });
// // console.log(res.data);
// setCategory(res?.data?.categories);
// };
// //3rd
// const [product, setProduct] = useState([]);
// const getAllProduct = async () => {
// let res = await axios.get(`/api/product/getAll/user/`, {
// headers: {
// Authorization: `Bearer ${token}`,
// },
// });
// // console.log(res.data);
// setProduct(res?.data?.product);
// };
// // 3rd
// const [Requests, setRequests] = useState([]);
// const getAllRequests = async () => {
// let res = await axios.get(`/api/contact/request/getAll/`, {
// headers: {
// Authorization: `Bearer ${token}`,
// },
// });
// // console.log(res.data);
// setRequests(res.data.contactRequest);
// };
// //3 requiment
// const [requirement, setRequirement] = useState([])
@ -118,17 +128,19 @@ const Dashboard = () => {
// }, [token]);
useEffect(() => {
getAllUsers();
getAllCategory();
getAllProduct();
getAllRequests();
getAllsalescoordinator();
// getAllCategory();
// getAllProduct();
// getAllRequests();
}, [token]);
return (
<>
<WidgetsDropdown
users={users}
category={category}
product={product}
Requests={Requests}
salescoordinator={salescoordinator}
// category={category}
// product={product}
// Requests={Requests}
/>
</>
);

View File

@ -18,126 +18,138 @@ import axios from "axios";
{
/* <BeatLoader color="#36d7b7" /> */
}
const WidgetsDropdown = ({ users,salescoordinator }) => {
// const WidgetsDropdown = ({ users, category, product, Requests }) => {
// const token = isAutheticated();
// const [orders, setOrders] = useState([]);
// const [todayorders, setTodayOrders] = useState([]);
// const [monthorders, setMonthOrders] = useState([]);
// const [yearorders, setYearOrders] = useState([]);
// const [lastyearorders, setLastYearOrders] = useState([]);
// const [processingorders, setProcessingOrders] = useState([]);
// const [dispatchedorders, setDispatchedOrders] = useState([]);
// const [deliveredorders, setDeliveredOrders] = useState([]);
// const [cancelledorders, setCancelledOrders] = useState([]);
// const getAllOrder = async () => {
// let res = await axios.get(`/api/order/getAll/`, {
// headers: {
// Authorization: `Bearer ${token}`,
// },
// });
// // console.log(res.data);
// setOrders(res?.data?.order);
// setTodayOrders(
// res?.data?.order?.filter((order) => {
// return (
// new Date(order.createdAt).toDateString() === new Date().toDateString()
// );
// })
// );
// setMonthOrders(
// res?.data?.order?.filter((order) => {
// return new Date(order.createdAt).getMonth() === new Date().getMonth();
// })
// );
// setYearOrders(
// res?.data?.order?.filter((order) => {
// return (
// new Date(order.createdAt).getFullYear() === new Date().getFullYear()
// );
// })
// );
// setLastYearOrders(
// res?.data?.order?.filter((order) => {
// return (
// new Date(order.createdAt).getFullYear() ===
// new Date().getFullYear() - 1
// );
// })
// );
// };
// const getProcessingOrder = async () => {
// let res = await axios.get(`/api/order/getAll/processing`, {
// headers: {
// Authorization: `Bearer ${token}`,
// },
// });
// // console.log(res.data);
// setProcessingOrders(res?.data?.order);
// };
// const getDispatchedOrder = async () => {
// let res = await axios.get(`/api/order/getAll/dispatched`, {
// headers: {
// Authorization: `Bearer ${token}`,
// },
// });
// // console.log(res.data);
// setDispatchedOrders(res?.data?.order);
// };
// const getDeliveredOrder = async () => {
// let res = await axios.get(`/api/order/getAll/delivered`, {
// headers: {
// Authorization: `Bearer ${token}`,
// },
// });
// // console.log(res.data);
// setDeliveredOrders(res?.data?.order);
// };
// const getCancelledOrder = async () => {
// let res = await axios.get(`/api/order/getAll/cancelled`, {
// headers: {
// Authorization: `Bearer ${token}`,
// },
// });
// // console.log(res.data);
// setCancelledOrders(res?.data?.order);
// };
const WidgetsDropdown = ({ users, category, product, Requests }) => {
const token = isAutheticated();
const [orders, setOrders] = useState([]);
const [todayorders, setTodayOrders] = useState([]);
const [monthorders, setMonthOrders] = useState([]);
const [yearorders, setYearOrders] = useState([]);
const [lastyearorders, setLastYearOrders] = useState([]);
const [processingorders, setProcessingOrders] = useState([]);
const [dispatchedorders, setDispatchedOrders] = useState([]);
const [deliveredorders, setDeliveredOrders] = useState([]);
const [cancelledorders, setCancelledOrders] = useState([]);
const getAllOrder = async () => {
let res = await axios.get(`/api/order/getAll/`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
// console.log(res.data);
setOrders(res?.data?.order);
setTodayOrders(
res?.data?.order?.filter((order) => {
return (
new Date(order.createdAt).toDateString() === new Date().toDateString()
);
})
);
setMonthOrders(
res?.data?.order?.filter((order) => {
return new Date(order.createdAt).getMonth() === new Date().getMonth();
})
);
setYearOrders(
res?.data?.order?.filter((order) => {
return (
new Date(order.createdAt).getFullYear() === new Date().getFullYear()
);
})
);
setLastYearOrders(
res?.data?.order?.filter((order) => {
return (
new Date(order.createdAt).getFullYear() ===
new Date().getFullYear() - 1
);
})
);
};
const getProcessingOrder = async () => {
let res = await axios.get(`/api/order/getAll/processing`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
// console.log(res.data);
setProcessingOrders(res?.data?.order);
};
const getDispatchedOrder = async () => {
let res = await axios.get(`/api/order/getAll/dispatched`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
// console.log(res.data);
setDispatchedOrders(res?.data?.order);
};
const getDeliveredOrder = async () => {
let res = await axios.get(`/api/order/getAll/delivered`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
// console.log(res.data);
setDeliveredOrders(res?.data?.order);
};
const getCancelledOrder = async () => {
let res = await axios.get(`/api/order/getAll/cancelled`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
// console.log(res.data);
setCancelledOrders(res?.data?.order);
};
useEffect(() => {
getAllOrder();
getProcessingOrder();
getDispatchedOrder();
getDeliveredOrder();
getCancelledOrder();
}, [token]);
const date = new Date();
const day = date.getDate();
const suffix =
day === 1 || day === 21 || day === 31
? "st"
: day === 2 || day === 22
? "nd"
: day === 3 || day === 23
? "rd"
: "th";
const month = date.toLocaleDateString("en-US", { month: "long" });
const formattedDate = `${day}${suffix} ${month}`;
// console.log(formattedDate);
const year = date.toLocaleDateString("en-US", { year: "numeric" });
const formattedmonth = `${month} ${year}`;
// useEffect(() => {
// getAllOrder();
// getProcessingOrder();
// getDispatchedOrder();
// getDeliveredOrder();
// getCancelledOrder();
// }, [token]);
// const date = new Date();
// const day = date.getDate();
// const suffix =
// day === 1 || day === 21 || day === 31
// ? "st"
// : day === 2 || day === 22
// ? "nd"
// : day === 3 || day === 23
// ? "rd"
// : "th";
// const month = date.toLocaleDateString("en-US", { month: "long" });
// const formattedDate = `${day}${suffix} ${month}`;
// // console.log(formattedDate);
// const year = date.toLocaleDateString("en-US", { year: "numeric" });
// const formattedmonth = `${month} ${year}`;
return (
<>
{/* <h4>Users and Requests</h4>
<h4>Principal Distributor</h4>
<CRow>
<CCol sm={6} lg={3}>
<CWidgetStatsA
className="mb-4"
color="primary"
value={<>{users.length}</>}
title="Total Users"
title="Total Principal Distributor"
/>
</CCol>
</CRow>
<h4>Sales CoOrdinator</h4>
<CRow>
<CCol sm={6} lg={3}>
<CWidgetStatsA
className="mb-4"
color="primary"
value={<>{salescoordinator}</>}
title="Total Sales CoOrdinator"
/>
</CCol>
</CRow>
{/* <CCol sm={6} lg={3}>
<CWidgetStatsA
className="mb-4"
color="primary"