diff --git a/src/components/pages/profile/SideNav/index.jsx b/src/components/pages/profile/SideNav/index.jsx
index 9f962ed..110ee53 100644
--- a/src/components/pages/profile/SideNav/index.jsx
+++ b/src/components/pages/profile/SideNav/index.jsx
@@ -3,12 +3,22 @@ import { AiTwotoneShopping } from "react-icons/ai";
import { FiLogOut } from 'react-icons/fi'
import { Button, Col, Modal } from 'react-bootstrap';
import { NavDiv , ProfileLink } from '../../../../styles/pages/profile-page'
-import React, { useState } from "react";
+import React, { useState, useEffect } from "react";
import { Slab } from "../../../../styles/themes/font-styles";
+import { fetchResult, postApi } from "../../../../services/api/loaded-services";
const SideNav = () =>{
const [show, setShow] = useState(false);
+ const [userData, setUserData] = useState({})
+ useEffect(() => {
+ async function fetchdata(){
+ await postApi("profile")
+ let res = await fetchResult("profile")
+ setUserData(res)
+ }
+ fetchdata()
+ }, [])
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
@@ -16,9 +26,9 @@ const SideNav = () =>{
return(
-
+
Hello,
- Gowthaman M
+ {userData.name}
My Orders
diff --git a/src/components/pages/profile/delivery/index.jsx b/src/components/pages/profile/delivery/index.jsx
index df65404..42f51de 100644
--- a/src/components/pages/profile/delivery/index.jsx
+++ b/src/components/pages/profile/delivery/index.jsx
@@ -1,25 +1,61 @@
import { useState, useEffect } from "react";
import { Col, Container, Row } from "react-bootstrap";
import { Input, StyledRow , StyledButton , Msg } from "../../../../styles/pages/delivery";
-import data from "../../../../api/DeliveryInfo.json";
import axios from "axios";
import { Slab } from "../../../../styles/themes/font-styles";
import { RiPencilFill } from "react-icons/ri";
import { FaEraser , FaSave } from "react-icons/fa";
import SideNav from "../SideNav";
import { NavDiv } from "../../../../styles/pages/profile-page";
+import { fetchResult, postApi } from "../../../../services/api/loaded-services";
+import { ApiPostService } from "../../../../services/api/api-services";
+import { retriveDetails } from "../../../../services/storage/details";
const DeliveryInformation = () =>{
- const [fname,setfName]=useState( data.fname )
- const [lname,setlName]=useState( data.lname )
- const [phno,setPhno]=useState( data.phno )
- const [address,setAddress]=useState( data.address )
- const [pin,setPin]=useState( data.pin )
- const [city,setCity]=useState( data.city )
- const [state,setState]=useState( data.state )
- const [err,setErr]=useState("")
- const [msg,setMsg]=useState("")
+ const [details,setDetails]= useState(
+ { fname:'', lname:'' , phno:'' , address:'' , pin:'' , city:'' ,state:'' }
+ )
+ const [msg,setMsg]=useState({ err:'', msg:'' })
+ const handleChange = e => {
+ const { name, value } = e.target;
+ setDetails(prevState => ({
+ ...prevState,
+ [name]: value
+ }));
+ };
+
+ function assign(data){
+ console.log('data', data)
+ var name=data.deliveryName.split(" ");
+ var pincode= data.pincode === 0 ? "" : data.pincode
+ setDetails({
+ 'fname':name[0] ,
+ 'lname': name[1],
+ 'phno':data.phoneNumber ,
+ 'address':data.address,
+ 'pin':pincode,
+ 'city':data.city,
+ 'state':data.state});
+ }
+
+ function messages(name, str){
+ setMsg(prevState => ({
+ ...prevState,
+ [name]: str
+ }));
+ }
+
+ let userId = retriveDetails()
+
+ useEffect(() => {
+ async function fetchdata(){
+ await postApi("profile")
+ let det = await fetchResult("delivery")
+ assign(det)
+ }
+ fetchdata()
+ }, [])
const edit= () =>{
var TextElements = document.getElementsByClassName("info");
@@ -30,32 +66,26 @@ const DeliveryInformation = () =>{
for (var i = 0, max = TextElements.length; i < max; i++) {
TextElements[i].removeAttribute("readOnly")
}
- setErr("")
- setMsg("")
+ messages('err',"")
+ messages('msg',"")
}
const reset= () =>{
- setfName("");
- setlName("");
- setPhno("");
- setAddress("");
- setPin("");
- setCity("");
- setState("");
+ setDetails({ fname:'', lname:'' , phno:'' , address:'' , pin:'' , city:'' ,state:'' })
}
const save =() =>{
- if (fname==="" || lname==="" || phno==='' || address==="" || pin===""|| city==="" || state==="") {
- setErr("All fields are required!")
+ if (details.fname==="" || details.lname==="" || details.phno==='' || details.address==="" || details.pin===""|| details.city==="" || details.state==="") {
+ messages('err',"All fields are required!")
return;
}
- if(phno.length<10 || phno.length>10){
- setErr('Enter a valid phone number!')
+ if(details.phno.length<10 || details.phno.length>10){
+ messages('err', 'Enter a valid phone number!')
return;
}
- if(pin.length<6 || pin.length>6){
- setErr('Enter a valid pincode!')
+ if(details.pin.length<6 || details.pin.length>6){
+ messages('err', 'Enter a valid pincode!')
return;
}
- setErr("")
+ messages('err','')
var TextElements = document.getElementsByClassName("info");
for (var i = 0, max = TextElements.length; i < max; i++) {
TextElements[i].readOnly = true;
@@ -63,32 +93,52 @@ const DeliveryInformation = () =>{
document.getElementById('clear').style['display']="none";
document.getElementById('save').style['display']="none";
document.getElementById('edit').style['display']="block";
- setMsg("Your Address have been Updated!")
- }
- let a={pin}
- useEffect(async () => {
- await axios.get(`https://api.postalpincode.in/pincode/`+a.pin)
- .then((res) => {
- console.log(res);
- let cy=res.data[0].PostOffice[0]
- setCity(cy.District)
- setState(cy.State)
- })
- .catch((err) => {
- console.log(err)
- setCity('')
- setState('')
+ let delName=details.fname+" "+details.lname;
+ let op = ApiPostService(process.env.REACT_APP_DELIVERYUPDATE, {
+ 'customer': userId.id,
+ 'phoneNumber': details.phno ,
+ 'address': details.address,
+ 'deliveryName': delName,
+ 'pincode': details.pin,
+ 'nation': 'India',
+ 'state': details.state,
+ 'city': details.city,
})
- },[pin])
+ messages('msg','Your Address have been Updated!')
+ }
+
+ useEffect(() => {
+ async function getpin(){
+ let a={details}
+ await axios.get(`https://api.postalpincode.in/pincode/`+a.details.pin)
+ .then((res) => {
+ let cy=res.data[0].PostOffice[0]
+ setDetails(prevState => ({
+ ...prevState,
+ city: cy.District,
+ state: cy.State
+ }));
+ })
+ .catch((err) => {
+ console.log(err)
+ setDetails(prevState => ({
+ ...prevState,
+ city: '',
+ state: ''
+ }));
+ })
+ }
+ getpin()
+ },[details.pin])
return (
-
+
-
+
Delivery Information
Clear
@@ -96,45 +146,45 @@ const DeliveryInformation = () =>{
-