diff --git a/src/views/Courier/Courier.js b/src/views/Courier/Courier.js
index 4faaca8..5483988 100644
--- a/src/views/Courier/Courier.js
+++ b/src/views/Courier/Courier.js
@@ -1,16 +1,8 @@
-import React, { useEffect } from 'react';
+import React, { useEffect, useState } from 'react';
import {
CAvatar,
CButton,
CButtonGroup,
- CCard,
- CCardBody,
- CCardFooter,
- CCardHeader,
- CCol,
- CContainer,
- CProgress,
- CRow,
CTable,
CTableBody,
CTableDataCell,
@@ -21,25 +13,64 @@ import {
import { Link } from 'react-router-dom';
import { isAutheticated } from 'src/auth';
import axios from 'axios';
+import Swal from 'sweetalert2';
+import { useHistory } from 'react-router-dom';
+
const Courier = () => {
const { token } = isAutheticated();
- console.log(token);
+ const [data, setData] = useState([])
+ const history = useHistory()
useEffect(() => {
const getData = async () => {
- const res = await axios.get('/api/vendor/view', {
+ const res = await axios.get('/api/courier', {
headers: {
"Access-Control-Allow-Origin": "*",
"Content-type": "Application/json",
"Authorization": `Bearer ${token}`
}
});
- console.log(res);
+ console.log(res.data);
+ setData(res.data.Pincode)
+ console.log(data);
}
getData();
}, []);
+ const handleDelete = async (id) => {
+ const res = await axios.delete(`/api/courier/${id}`, {
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ "Content-type": "Application/json",
+ "Authorization": `Bearer ${token}`
+ }
+ })
+ if ((res.data.message === "Success")) {
+ Swal.fire({
+ title: 'Updated',
+ text: 'Courier Deleted',
+ icon: 'success',
+ confirmButtonText: 'Cool',
+ confirmButtonColor: '#303c54',
+ iconColor: '#303c54'
+ }).then(() => {
+ history.push('/courier');
+ });
+ } else {
+ Swal("Oops!", "Something went wrong!", "error");
+ }
+
+ }
+ const formatDate = (date) => {
+ let today = new Date(date);
+ let dd = String(today.getDate()).padStart(2, '0');
+ let mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
+ let yyyy = today.getFullYear();
+
+ today = dd + '/' + mm + '/' + yyyy;
+ return today
+ }
return
+Add New
@@ -54,19 +85,22 @@ const Courier = () => {
Actions
-
-
- FedEx
- 123
- 123-1234-123
-
-
- Edit
- Delete
-
-
-
-
+
+ {data.map(item =>
+
+ {item.name} |
+ {item._id} |
+ {formatDate(item.createdAt)} |
+
+
+ Edit
+ handleDelete(item._id)}>Delete
+
+ |
+
+ )}
+
+
;
};
diff --git a/src/views/Courier/EditCourier.js b/src/views/Courier/EditCourier.js
new file mode 100644
index 0000000..2c8e28e
--- /dev/null
+++ b/src/views/Courier/EditCourier.js
@@ -0,0 +1,146 @@
+import React, { useEffect } from 'react';
+import {
+ CButton,
+ CCard,
+ CCardBody,
+ CCardGroup,
+ CCol,
+ CContainer,
+ CForm,
+ CFormInput,
+ CInputGroup,
+ CInputGroupText,
+ CRow,
+} from '@coreui/react'
+import CIcon from '@coreui/icons-react'
+import { cil3d } from '@coreui/icons'
+import { useState } from 'react';
+import axios from 'axios';
+import { isAutheticated } from 'src/auth';
+import { useParams } from 'react-router-dom';
+import Swal from 'sweetalert2';
+import { useHistory } from 'react-router-dom';
+
+const EditCourier = () => {
+ // const [id, setId] = useState(0);
+ const [date, setDate] = useState('')
+ const [courier, setCourier] = useState()
+ const { token } = isAutheticated();
+ const { id } = useParams();
+ const [data, setData] = useState([])
+ const history = useHistory();
+ useEffect(() => {
+ const getData = async () => {
+ const res = await axios.get(`/api/courier/${id}`, {
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ "Content-type": "Application/json",
+ "Authorization": `Bearer ${token}`
+ }
+ });
+ console.log(res.data);
+ setData(res.data?.Pincode[0])
+ setCourier(res.data?.Pincode[0].name)
+ console.log(data);
+ }
+ getData();
+
+ }, []);
+
+ useEffect(() => {
+ const getDate = () => {
+ let today = new Date();
+ let dd = String(today.getDate()).padStart(2, '0');
+ let mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
+ let yyyy = today.getFullYear();
+
+ today = dd + '/' + mm + '/' + yyyy;
+ return today
+ }
+
+
+ const generateCode = () => {
+ // setId(Math.round(Math.random() * 1000000000))
+ }
+ generateCode()
+ setDate(getDate())
+ }, [])
+ const handleChange = (e) => {
+ const { name, value } = e.target;
+ setCourier(value)
+ }
+ const handleClick = async () => {
+ let res = await axios.put(`/api/courier/${id}`, { name: courier }, {
+ headers: {
+ "Authorization": `Bearer ${token}`
+ }
+ })
+ if ((res.data.message === "Success")) {
+ Swal.fire({
+ title: 'Updated',
+ text: 'Courier Updated',
+ icon: 'success',
+ confirmButtonText: 'Cool',
+ confirmButtonColor: '#303c54',
+ iconColor: '#303c54'
+ }).then(() => {
+ history.push('/courier');
+ });
+ } else {
+ Swal("Oops!", "Something went wrong!", "error");
+ }
+ }
+ const formatDate = (date) => {
+ let today = new Date(date);
+ let dd = String(today.getDate()).padStart(2, '0');
+ let mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
+ let yyyy = today.getFullYear();
+
+ today = dd + '/' + mm + '/' + yyyy;
+ return today
+ }
+
+
+ return
+
+
+
+
+ Edit Courier
+ Fill the fields and submit to add a new vendor
+
+ Unique ID:
+ {id}
+ {/* (auto-generated)
*/}
+
+
+ Added On:
+ {formatDate(data.createdAt)}
+ {/* (auto-generated)
*/}
+
+
+
+
+
+
+
+
+
+ Submit
+
+
+
+
+
+
+
+
;
+};
+
+export default EditCourier;
diff --git a/src/views/Vendor/AddVendor.js b/src/views/Vendor/AddVendor.js
index b858fcb..c20b7ed 100644
--- a/src/views/Vendor/AddVendor.js
+++ b/src/views/Vendor/AddVendor.js
@@ -13,6 +13,7 @@ import {
CInputGroupText,
CRow,
} from '@coreui/react'
+import Swal from 'sweetalert2';
import CIcon from '@coreui/icons-react'
import { Country, State, City } from 'country-state-city';
import { cilGlobeAlt, cilLocationPin, cilLockLocked, cilUser } from '@coreui/icons'
@@ -22,6 +23,7 @@ import { useEffect } from 'react';
import axios from 'axios';
import { getAllStates, getStatesOfCountry, getCitiesOfCountry } from 'country-state-city/dist/lib/state';
import { isAutheticated } from 'src/auth';
+import { useHistory } from 'react-router-dom';
const AddVendor = () => {
@@ -32,7 +34,9 @@ const AddVendor = () => {
country: 'India',
address_1: '',
address_2: '',
+
})
+ const history = useHistory()
const { token } = isAutheticated();
const [states, setStates] = useState([]);
const [cities, setCities] = useState([]);
@@ -64,13 +68,24 @@ const AddVendor = () => {
}, [vendor.country, vendor.state, countryCode, stateCode]);
const handleClick = async () => {
- let res = await axios.post('/api/vendor/add', vendor, {
+ let res = await axios.post('/api/vendor/add', { ...vendor, code }, {
headers: {
"Authorization": `Bearer ${token}`
}
})
- if (res) {
- console.log(res.data);
+ if ((res.data.message === "Success")) {
+ Swal.fire({
+ title: 'Done',
+ text: 'Vendor Added',
+ icon: 'success',
+ confirmButtonText: 'ok',
+ confirmButtonColor: '#303c54',
+ iconColor: '#303c54'
+ }).then(() => {
+ history.push('/courier');
+ });
+ } else {
+ Swal("Oops!", "Something went wrong!", "error");
}
}
diff --git a/src/views/Vendor/EditVendor.js b/src/views/Vendor/EditVendor.js
new file mode 100644
index 0000000..df783bf
--- /dev/null
+++ b/src/views/Vendor/EditVendor.js
@@ -0,0 +1,192 @@
+import React from 'react';
+import {
+ CButton,
+ CCard,
+ CCardBody,
+ CCardGroup,
+ CCol,
+ CContainer,
+ CForm,
+ CFormInput,
+ CFormSelect,
+ CInputGroup,
+ CInputGroupText,
+ CRow,
+} from '@coreui/react'
+import CIcon from '@coreui/icons-react'
+import { Country, State, City } from 'country-state-city';
+import { cilGlobeAlt, cilLocationPin, cilLockLocked, cilUser } from '@coreui/icons'
+import { Link } from 'react-router-dom';
+import { useState } from 'react';
+import { useEffect } from 'react';
+import axios from 'axios';
+import { getAllStates, getStatesOfCountry, getCitiesOfCountry } from 'country-state-city/dist/lib/state';
+import { isAutheticated } from 'src/auth';
+import { useParams } from 'react-router-dom';
+import Swal from 'sweetalert2';
+import { useHistory } from 'react-router-dom';
+
+
+const AddVendor = () => {
+ const [vendor, setVendor] = useState({
+ vendor_name: '',
+ city: '',
+ state: 'Andhra Pradesh',
+ country: 'India',
+ address_1: '',
+ address_2: '',
+ })
+ const history = useHistory()
+ const { id } = useParams();
+ const { token } = isAutheticated();
+ const [states, setStates] = useState([]);
+ const [cities, setCities] = useState([]);
+ const [countryCode, setCountryCode] = useState('IN')
+ const [stateCode, setStateCode] = useState('AP')
+ const countries = Country.getAllCountries();
+ const allStates = State.getAllStates();
+ const [data, setData] = useState([]);
+ // const Code = Math.round(Math.random() * 1000000000);
+ const handleChange = (e) => (event) => {
+ setVendor({ ...vendor, [e]: event.target.value });
+ };
+ useEffect(() => {
+ const getData = async () => {
+ const res = await axios.get(`api/vendor/view/${id}`, {
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ "Content-type": "Application/json",
+ "Authorization": `Bearer ${token}`
+ }
+ });
+ if (res) {
+ setData(res?.data?.Store)
+ setVendor(res?.data?.Store)
+ }
+
+
+ console.log(res.data);
+ }
+ getData();
+
+
+ }, []);
+ // console.log(vendor);
+ useEffect(() => {
+ const ccode = countries.find(item => item.name === vendor.country)
+ const scode = allStates.find(item => item.name === vendor.state)
+ console.log(ccode.isoCode + ":" + scode.isoCode);
+ console.log(vendor.country, vendor.state);
+ setCountryCode(ccode.isoCode)
+ setStateCode(scode.isoCode)
+ setStates(prev => State.getStatesOfCountry(countryCode))
+ setCities(prev => City.getCitiesOfState(countryCode, stateCode))
+ }, [vendor.country, vendor.state, countryCode, stateCode]);
+ console.log(data);
+ const handleClick = async () => {
+ let res = await axios.put(`/api/vendor/${id}`, vendor, {
+ headers: {
+ "Authorization": `Bearer ${token}`
+ }
+ })
+ if ((res.data.message === "Success")) {
+ Swal.fire({
+ title: 'Done',
+ text: 'vendor Updated',
+ icon: 'success',
+ confirmButtonText: 'Cool',
+ confirmButtonColor: '#303c54',
+ iconColor: '#303c54'
+ }).then(() => {
+ history.push('/vendors');
+ });
+ } else {
+ Swal("Oops!", "Something went wrong!", "error");
+ }
+ }
+
+ return
+
+
+
+
+ Edit Vendor
+ {/* Fill the fields and submit to add a new vendor
*/}
+
+ Code:
+ {data?.code}
+ {/* (auto-generated)
*/}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ countries.map((item) =>
+
+ )
+ }
+
+
+ {
+ states.map((item) =>
+
+ )
+ }
+
+
+ {
+ cities.map((item) =>
+
+ )
+ }
+
+
+
+ Submit
+
+
+
+
+
+
+
+
;
+};
+
+export default AddVendor;
diff --git a/src/views/Vendor/Vendor.js b/src/views/Vendor/Vendor.js
index 016bf80..298d5ec 100644
--- a/src/views/Vendor/Vendor.js
+++ b/src/views/Vendor/Vendor.js
@@ -3,14 +3,6 @@ import {
CAvatar,
CButton,
CButtonGroup,
- CCard,
- CCardBody,
- CCardFooter,
- CCardHeader,
- CCol,
- CContainer,
- CProgress,
- CRow,
CTable,
CTableBody,
CTableDataCell,
@@ -21,10 +13,14 @@ import {
import { Link } from 'react-router-dom';
import axios from 'axios';
import { isAutheticated } from '../../auth';
+import { useState } from 'react';
+import { useHistory } from 'react-router-dom';
+import Swal from 'sweetalert2';
const Vendor = () => {
const { token } = isAutheticated();
- console.log(token);
+ const history = useHistory();
+ const [data, setData] = useState([]);
useEffect(() => {
const getData = async () => {
@@ -35,12 +31,42 @@ const Vendor = () => {
"Authorization": `Bearer ${token}`
}
});
- console.log(res);
+ if (res) {
+ setData(res?.data?.Stores)
+ }
+
+
+ console.log(res.data);
}
getData();
+ data.map(item => console.log(item.city))
}, []);
+ console.log(data);
+ const handleDelete = async (id) => {
+ const res = await axios.delete(`/api/vendor/${id}`, {
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ "Content-type": "Application/json",
+ "Authorization": `Bearer ${token}`
+ }
+ })
+ if ((res.data.message === 'Deleted Successfully')) {
+ Swal.fire({
+ title: 'Done',
+ text: 'Vendor Deleted',
+ icon: 'success',
+ confirmButtonText: 'Cool',
+ confirmButtonColor: '#303c54',
+ iconColor: '#303c54'
+ }).then(() => {
+ history.push('/vendors');
+ });
+ } else {
+ Swal("Oops!", "Something went wrong!", "error");
+ }
+ }
return
@@ -57,20 +83,37 @@ const Vendor = () => {
Actions
-
-
- Mark
- 123
- Otto
-
-
- Edit
- View
- Delete
-
-
-
-
+
{data.map(item => {item.vendor_name} |
+ {item.code} |
+ {item.city} |
+
+
+ Edit
+
+ View
+ handleDelete(item._id)}>Delete
+ |
+
)}
+ {/*
+ {data?.map(item => {
+
+
+ {item.city}
+ {item.vendor_name}
+ {item.code}
+ {item.city}
+
+
+ Edit
+ View
+ Delete
+
+
+
+ })}
+
+
+ */}
;
};