diff --git a/src/routes.js b/src/routes.js index 6d7d0e9..4246596 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1,8 +1,8 @@ import React from 'react' - const AirwaysBill = React.lazy(() => import('./views/AirwaysBill/AirwaysBill')) const AddAirwaysBill = React.lazy(() => import('./views/AirwaysBill/AddAirwaysBill')) +const AirwayBillDetail = React.lazy(() => import('./views/AirwaysBill/AirwayBillDetail')) const Courier = React.lazy(() => import('./views/Courier/Courier')) const EditCourier = React.lazy(() => import('./views/Courier/EditCourier')) const AddCourier = React.lazy(() => import('./views/Courier/AddCourier')) @@ -70,6 +70,7 @@ const routes = [ { path: '/addcourier', name: 'Courier / Add Courier', component: AddCourier }, { path: '/airwaysbill', name: 'Airways Bill', component: AirwaysBill }, { path: '/addairwaysbill', name: 'Airways Bill / Add New Entry', component: AddAirwaysBill }, + { path: '/viewbill/:id', name: 'View Bill', component: AirwayBillDetail }, , { path: '/vendors', name: 'Vendors', component: Vendor }, { path: '/editvendor/:id', name: 'Edit Vendor', component: EditVendor }, { path: '/viewvendor/:id', name: 'View Vendor', component: VendorDetail }, diff --git a/src/views/AirwaysBill/AddAirwaysBill.js b/src/views/AirwaysBill/AddAirwaysBill.js index 5250522..76f66ca 100644 --- a/src/views/AirwaysBill/AddAirwaysBill.js +++ b/src/views/AirwaysBill/AddAirwaysBill.js @@ -18,6 +18,8 @@ import { cil3d, cilAirplaneMode, cilGlobeAlt, cilLocationPin, cilLockLocked, cil import { useState } from 'react'; import axios from 'axios'; import { isAutheticated } from 'src/auth'; +import { useHistory } from 'react-router-dom'; +import Swal from 'sweetalert2'; const AddAirwaysBill = () => { @@ -27,17 +29,28 @@ const AddAirwaysBill = () => { city: '', state: 'Andhra Pradesh', country: 'India', - address_1: '', - address_2: '', - + from_address_1: '', + from_address_2: '', + to_address_1: '', + to_name: '', + to_address_2: '', + AWB: '', + courier: '' }) + const [showCouriers, setShowCouriers] = useState([]) + const [showVendors, setShowVendors] = useState([]) const [code, setCode] = useState() + const history = useHistory() + useEffect(() => { const generateCode = () => { setCode(Math.round(Math.random() * 1000000000)) } + + const getData = async () => { - const res = await axios.get('/api/vendor/view', + + const couriers = await axios.get('/api/courier', { headers: { "Access-Control-Allow-Origin": "*", @@ -45,11 +58,25 @@ const AddAirwaysBill = () => { "Authorization": `Bearer ${token}` } }) - console.log(res.data.Stores); + const vendors = await axios.get('/api/vendor/view', + { + headers: { + "Access-Control-Allow-Origin": "*", + "Content-type": "Application/json", + "Authorization": `Bearer ${token}` + } + }) + + console.log(couriers.data.Pincode); + console.log(vendors.data.Stores); + setShowVendors(vendors.data.Stores) + setShowCouriers(couriers.data.Pincode) } getData(); generateCode() }, []) + + const formatDate = () => { let today = new Date(); let dd = String(today.getDate()).padStart(2, '0'); @@ -60,6 +87,32 @@ const AddAirwaysBill = () => { return today } + const handleChange = (e) => (event) => { + setBill({ ...bill, [e]: event.target.value }); + }; + const handleClick = async () => { + let res = await axios.post('/api/airways/add', { ...bill, code }, { + headers: { + "Authorization": `Bearer ${token}` + } + }) + if ((res.data.message === "Success")) { + console.log(res.data); + Swal.fire({ + title: 'Done', + text: 'Bill Added', + icon: 'success', + confirmButtonText: 'ok', + confirmButtonColor: '#303c54', + iconColor: '#303c54' + }).then(() => { + history.push('/airwaysbill') + }); + } else { + Swal("Oops!", "Something went wrong!", "error"); + } + } + return
@@ -69,7 +122,7 @@ const AddAirwaysBill = () => {

Fill the fields and submit to add a new bill

ID:

-
5324756898
+
{code}
{/*

(auto-generated)

*/}
@@ -83,13 +136,14 @@ const AddAirwaysBill = () => { + onChange={handleChange('vendor_name')} + > + { + showVendors.map((item) => + + ) + } + @@ -98,12 +152,14 @@ const AddAirwaysBill = () => { @@ -114,6 +170,7 @@ const AddAirwaysBill = () => { type="text" placeholder="To (Name)" autoComplete="toname" + onChange={handleChange('to_name')} /> @@ -124,12 +181,14 @@ const AddAirwaysBill = () => { @@ -138,13 +197,15 @@ const AddAirwaysBill = () => { + onChange={handleChange('courier')} + > + { + showCouriers.map((item) => + + ) + } + + @@ -153,9 +214,10 @@ const AddAirwaysBill = () => { type="text" placeholder="AWB" autoComplete="AWB" + onChange={handleChange('AWB')} /> - + handleClick()}> Submit diff --git a/src/views/AirwaysBill/AirwayBillDetail.js b/src/views/AirwaysBill/AirwayBillDetail.js new file mode 100644 index 0000000..9eca441 --- /dev/null +++ b/src/views/AirwaysBill/AirwayBillDetail.js @@ -0,0 +1,88 @@ +import React, { useEffect, useState } from 'react'; +import { + CTable, + CTableBody, + CTableDataCell, + CTableHead, + CTableHeaderCell, + CTableRow, +} from '@coreui/react' +import { useParams } from 'react-router-dom'; +import axios from 'axios'; +import { isAutheticated } from '../../auth'; + + + +const AirwayBillDetail = () => { + const [data, setData] = useState({}); + const { id } = useParams() + const { token } = isAutheticated(); + + useEffect(() => { + const getData = async () => { + const res = await axios.get(`/api/airways/view/${id}`, { + headers: { + "Access-Control-Allow-Origin": "*", + "Content-type": "Application/json", + "Authorization": `Bearer ${token}` + } + }); + if (res) { + setData(res?.data?.Store) + } + + } + getData(); + }, []); + console.log(data); + 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
+

Bill Details

+ + + + Unique ID + {data._id} + + + + + Code + {data.code} + + + AWB + {data.AWB} + + + Vendor Name + {data.vendor_name} + + + Added On + {formatDate(data.createdAt)} + + + From Address + {data.from_address_1},{data.from_address_2},{data.city},{data.state},{data.country} + + + To Address + {data.to_address_1},{data.to_address_2} + + + +
; +}; + +export default AirwayBillDetail; diff --git a/src/views/AirwaysBill/AirwaysBill.js b/src/views/AirwaysBill/AirwaysBill.js index cf8bd10..311a14d 100644 --- a/src/views/AirwaysBill/AirwaysBill.js +++ b/src/views/AirwaysBill/AirwaysBill.js @@ -24,11 +24,11 @@ import axios from 'axios'; const AirwaysBill = () => { const { token } = isAutheticated(); - console.log(token); + const [data, setData] = useState([]) useEffect(() => { const getData = async () => { - const res = await axios.get('/api/vendor/view', { + const res = await axios.get('/api/airways/view', { headers: { "Access-Control-Allow-Origin": "*", "Content-type": "Application/json", @@ -36,10 +36,20 @@ const AirwaysBill = () => { } }); console.log(res.data); + setData(res.data.Stores) } getData(); }, []); + 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
@@ -59,21 +69,25 @@ const AirwaysBill = () => { Action - - - Mark - 123 - Otto - 123 - Otto - - - View + + {data.map(item => + + {item.code} + {item.vendor_name} + {formatDate(item.createdAt)} + {item.to_name} + {item.AWB} + + + View - - - - + + + + + )} + +
; }; diff --git a/src/views/Courier/Courier.js b/src/views/Courier/Courier.js index d0871fe..a857af2 100644 --- a/src/views/Courier/Courier.js +++ b/src/views/Courier/Courier.js @@ -20,7 +20,7 @@ import { useHistory } from 'react-router-dom'; const Courier = () => { const { token } = isAutheticated(); const [data, setData] = useState([]) - const history = useHistory() + const [reload, setReload] = useState(false) useEffect(() => { const getData = async () => { @@ -37,7 +37,7 @@ const Courier = () => { } getData(); - }, []); + }, [reload]); const handleDelete = async (id) => { const res = await axios.delete(`/api/courier/${id}`, { headers: { @@ -56,7 +56,8 @@ const Courier = () => { iconColor: '#303c54' }).then(() => { // history.push('/courier'); - location.reload(); + // location.reload(); + setReload(!reload) }); } else { Swal("Oops!", "Something went wrong!", "error"); diff --git a/src/views/Vendor/AddVendor.js b/src/views/Vendor/AddVendor.js index a16ad57..0c9f481 100644 --- a/src/views/Vendor/AddVendor.js +++ b/src/views/Vendor/AddVendor.js @@ -82,7 +82,7 @@ const AddVendor = () => { confirmButtonColor: '#303c54', iconColor: '#303c54' }).then(() => { - history.push('/courier'); + history.push('/vendors'); }); } else { Swal("Oops!", "Something went wrong!", "error"); diff --git a/src/views/Vendor/Vendor.js b/src/views/Vendor/Vendor.js index 608b7f2..499735f 100644 --- a/src/views/Vendor/Vendor.js +++ b/src/views/Vendor/Vendor.js @@ -21,6 +21,7 @@ const Vendor = () => { const { token } = isAutheticated(); const history = useHistory(); const [data, setData] = useState([]); + const [reload, setReload] = useState(false); useEffect(() => { const getData = async () => { @@ -36,12 +37,12 @@ const Vendor = () => { } - console.log(res.data); + } getData(); - data.map(item => console.log(item.city)) - }, []); + + }, [reload]); console.log(data); const handleDelete = async (id) => { @@ -62,7 +63,8 @@ const Vendor = () => { iconColor: '#303c54' }).then(() => { // history.('/vendors'); - location.reload(); + setReload(!reload) + // location.reload(); }); } else { Swal("Oops!", "Something went wrong!", "error");