Commit 9576e68a by jay

vendor sign in, otp, business details

1 parent edc08403
......@@ -2,14 +2,22 @@ import { getSession, signOut } from "next-auth/react";
import Image from "next/image";
import Link from "next/link";
import React, { useEffect, useState } from "react";
import { useSelector } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { cleanImage } from "../../services/imageHandling";
import { Button, Container, Form, Nav, Navbar } from "react-bootstrap";
import { loadUser } from "../../redux/actions/userActions";
const Header = () => {
const { user, error } = useSelector(state => state.loadedUser);
const dispatch = useDispatch();
console.log("user", user);
const [isSticky, setIsSticky] = useState(false);
useEffect(() => {
dispatch(loadUser());
}, []);
useEffect(() => {
const handleScroll = () => {
// Check if the scroll position is greater than a certain threshold
const scrollY = window.scrollY || window.pageYOffset;
......@@ -17,15 +25,15 @@ const Header = () => {
};
// Attach the scroll event listener when the component mounts
window.addEventListener('scroll', handleScroll);
window.addEventListener("scroll", handleScroll);
// Clean up the event listener when the component unmounts
return () => {
window.removeEventListener('scroll', handleScroll);
window.removeEventListener("scroll", handleScroll);
};
}, []);
return (
<header className={`header_wrap ${isSticky ? 'stick' : ''}`}>
<header className={`header_wrap ${isSticky ? "stick" : ""}`}>
<Navbar expand="lg" className="bg-body-tertiary">
<Container fluid>
<Navbar.Brand href="#">
......@@ -54,12 +62,23 @@ const Header = () => {
</Button>
</div>
</Form>
{/* {console.log(user.id)} */}
{(user && user.id) ? (
<div>
{console.log("here")}
<div><p>Brand Logo</p></div>
<p>{user.phone}</p>
</div>
) : (
<div>
<Button className="me-3" variant="primary">
Sign Up
</Button>
<Button className="" variant="primary">
Log In
</Button>
</div>
)}
</Navbar.Collapse>
</Container>
</Navbar>
......
......@@ -13,6 +13,7 @@ import { registerUser } from "../../redux/actions/userActions";
import { toast } from "react-toastify";
import OTPInput from "../common-components/OTPInput";
import { finishVendorOtpVerification } from "../../redux/actions/vendorActions";
import { signIn } from "next-auth/react";
const Signup = props => {
console.log(props.type);
......@@ -35,7 +36,7 @@ const Signup = props => {
};
const signupValidationSchema = Yup.object().shape({
fullname: Yup.string().required("Fullname is Required"),
fullname: Yup.string().required("Full name is required"),
email: Yup.string().required("Email Id is Required").email("Please Enter An Valid Email Id"),
password: Yup.string().required("Password is Required").min(6, "Password must be minimum 6 characters"),
confirmPassword: Yup.string()
......@@ -74,6 +75,8 @@ const Signup = props => {
}
};
// console.log("otp", otp);
return (
<Fragment>
<div className="contaier-fluid login-banner-image">
......@@ -130,14 +133,23 @@ const Signup = props => {
const otpRes = await finishVendorOtpVerification({ email: values.email, oneTimePassword });
console.log("otpRes", otpRes);
if (otpRes.data.ok) {
// router.push("/thank-you")
toast.success("User registered successflly");
const result = await signIn("credentials", {
email: values.email,
password: values.password,
redirect: false
});
console.log("result", result);
router.push("/vendor/business-details");
// toast.success("User registered successflly");
} else if (!otpRes.data.ok) {
setOtp(new Array(4).fill(""));
toast.error("Invalid OTP, please try again.");
}
}
}}
>
<div className="input-group">
<label>Fullname</label>
<label>Full Name</label>
<input type="text" name="fullname" onChange={handleChange} onBlur={handleBlur} value={values.fullname} placeholder="Your name" />
{errors.fullname && touched.fullname && <span className="form-error">{errors.fullname}</span>}
</div>
......
import { Formik } from "formik";
import { Fragment } from "react";
import { Fragment, useEffect, useRef, useState } from "react";
import { Button, Form } from "react-bootstrap";
import * as Yup from "yup";
import { FaArrowRight, FaTimes } from "react-icons/fa";
import Image from "next/image";
import { getSession } from "next-auth/react";
import "react-bootstrap-typeahead/css/Typeahead.css";
import { useDispatch } from "react-redux";
import { getLoggedInVendor } from "../../redux/actions/vendorActions";
const BusinessDetails = () => {
const [session, setSession] = useState(null);
const dispatch = useDispatch()
// const [pincodeData, setPinCodeData] = useState()
// const ref = useRef(null);
useEffect(() => {
const fetchSession = async () => {
setSession(await getSession());
};
fetchSession();
}, []);
console.log("session", session);
const businessDetailsValidationSchema = Yup.object().shape({
panNumber: Yup.string()
.required("Pan Number is Required"),
panFile: Yup.mixed()
.required("Pan Image is Required"),
gstNumber: Yup.string()
.required("GST Number is Required"),
gstCertificateFile: Yup.mixed()
.required("GST Certificate is Required"),
businessName: Yup.string()
.required("Business Name is Required"),
brandLogoFile: Yup.mixed()
.required("Brand Logo is Required"),
pincode: Yup.string()
.required("Pincode is Required"),
country: Yup.string()
.required("Country is Required"),
state: Yup.string()
.required("State is Required"),
city: Yup.string()
.required("City is Required"),
addressLine1: Yup.string()
.required("Address Line 1 is Required"),
addressLine2: Yup.string()
.required("Address Line 2 is Required"),
panNumber: Yup.string().required("Pan Number is Required"),
panFile: Yup.mixed().required("Pan Image is Required"),
gstNumber: Yup.string().required("GST Number is Required"),
gstCertificateFile: Yup.mixed().required("GST Certificate is Required"),
businessName: Yup.string().required("Business Name is Required"),
brandLogoFile: Yup.mixed().required("Brand Logo is Required"),
pincode: Yup.string().required("Pincode is Required"),
country: Yup.string().required("Country is Required"),
state: Yup.string().required("State is Required"),
city: Yup.string().required("City is Required"),
addressLine1: Yup.string().required("Address Line 1 is Required"),
addressLine2: Yup.string().required("Address Line 2 is Required")
});
// const handleSearch = async pin => {
// let pincodeDataSet = await pincodeSearchByFilter(pin);
// console.log("pincodeData", pincodeDataSet.data.data);
// setPinCodeData(pincodeDataSet.data.data)
// };
return (
<Fragment>
<div className="container p-5">
......@@ -41,8 +50,12 @@ const BusinessDetails = () => {
<div className="content-div business-details">
<h2>Tell us about your business</h2>
<p>Please have the following ready before you begin</p>
<p><FaArrowRight /> Your bank account details for receiving payments from ZanGO</p>
<p className="mb-4"><FaArrowRight /> Tax (GST/PAN) details of your business.</p>
<p>
<FaArrowRight /> Your bank account details for receiving payments from ZanGO
</p>
<p className="mb-4">
<FaArrowRight /> Tax (GST/PAN) details of your business.
</p>
<hr />
<div className="form-container mt-4">
<Formik
......@@ -62,8 +75,20 @@ const BusinessDetails = () => {
}}
validationSchema={businessDetailsValidationSchema}
// enableReinitialize={true}
onSubmit={values => {
console.log("business details values", values)
onSubmit={async values => {
console.log("business details values", values);
const businessDetails = {
pan: values.panNumber,
gst: values.gstNumber,
businessName: values.businessName,
state: values.state,
city: values.city,
pincode: values.pincode,
country: values.country
};
// await dispatch(updateVendorBusinessDetails({businessDetails, }))
dispatch(getLoggedInVendor())
}}
>
{({ values, errors, touched, handleChange, handleBlur, handleSubmit, setFieldValue }) => (
......@@ -80,14 +105,8 @@ const BusinessDetails = () => {
<div className="col-12 col-lg-5">
<div className="input-group">
<label>Enter Business PAN No.</label>
<input
type="text"
name="panNumber"
onChange={handleChange}
onBlur={handleBlur}
value={values.panNumber}
/>
{errors.panNumber && touched.panNumber && (<span className="form-error">{errors.panNumber}</span>)}
<input type="text" name="panNumber" onChange={handleChange} onBlur={handleBlur} value={values.panNumber} />
{errors.panNumber && touched.panNumber && <span className="form-error">{errors.panNumber}</span>}
</div>
</div>
<div className="col-12 offset-lg-1 col-lg-5">
......@@ -99,10 +118,10 @@ const BusinessDetails = () => {
className="custom-file-input"
id="panFile"
name="panFile"
onChange={(event) => {
onChange={event => {
if (event) {
const file = event.currentTarget.files[0]
setFieldValue("panFile", file)
const file = event.currentTarget.files[0];
setFieldValue("panFile", file);
}
}}
onBlur={handleBlur}
......@@ -117,13 +136,16 @@ const BusinessDetails = () => {
</label>
</div>
<p className="textS">Upload in .PNG or .JPG/JPEG format</p>
{errors.panFile && touched.panFile && (<span className="form-error">{errors.panFile}</span>)}
{errors.panFile && touched.panFile && <span className="form-error">{errors.panFile}</span>}
{values.panFile && (
<div className="d-flex align-items-center justify-content-between p-1" style={{ width: "100%" }}>
<p className="textS m-0">{values.panFile.name}</p>
<FaTimes style={{ cursor: "pointer" }} onClick={() => {
setFieldValue("panFile", "")
}} />
<FaTimes
style={{ cursor: "pointer" }}
onClick={() => {
setFieldValue("panFile", "");
}}
/>
</div>
)}
</div>
......@@ -133,14 +155,8 @@ const BusinessDetails = () => {
<div className="col-12 col-lg-5">
<div className="input-group">
<label>GST Number</label>
<input
type="text"
name="gstNumber"
onChange={handleChange}
onBlur={handleBlur}
value={values.gstNumber}
/>
{errors.gstNumber && touched.gstNumber && (<span className="form-error">{errors.gstNumber}</span>)}
<input type="text" name="gstNumber" onChange={handleChange} onBlur={handleBlur} value={values.gstNumber} />
{errors.gstNumber && touched.gstNumber && <span className="form-error">{errors.gstNumber}</span>}
</div>
</div>
<div className="col-12 offset-lg-1 col-lg-5">
......@@ -161,7 +177,7 @@ const BusinessDetails = () => {
</label>
</div>
<p className="textS">Upload in .PNG or .JPG/JPEG format</p>
{errors.gstCertificateFile && touched.gstCertificateFile && (<span className="form-error">{errors.gstCertificateFile}</span>)}
{errors.gstCertificateFile && touched.gstCertificateFile && <span className="form-error">{errors.gstCertificateFile}</span>}
</div>
</div>
</div>
......@@ -169,14 +185,8 @@ const BusinessDetails = () => {
<div className="col-12 col-lg-5">
<div className="input-group">
<label>Business Name</label>
<input
type="text"
name="businessName"
onChange={handleChange}
onBlur={handleBlur}
value={values.businessName}
/>
{errors.businessName && touched.businessName && (<span className="form-error">{errors.businessName}</span>)}
<input type="text" name="businessName" onChange={handleChange} onBlur={handleBlur} value={values.businessName} />
{errors.businessName && touched.businessName && <span className="form-error">{errors.businessName}</span>}
</div>
</div>
<div className="col-12 offset-lg-1 col-lg-5">
......@@ -197,7 +207,7 @@ const BusinessDetails = () => {
</label>
</div>
<p className="textS">Upload in .PNG or .JPG/JPEG format</p>
{errors.brandLogoFile && touched.brandLogoFile && (<span className="form-error">{errors.brandLogoFile}</span>)}
{errors.brandLogoFile && touched.brandLogoFile && <span className="form-error">{errors.brandLogoFile}</span>}
</div>
</div>
</div>
......@@ -209,29 +219,36 @@ const BusinessDetails = () => {
<div className="col-12 col-lg-5">
<div className="input-group">
<label>Pincode</label>
<input
type="text"
name="pincode"
onChange={handleChange}
onBlur={handleBlur}
{/* <AsyncTypeahead
onSearch={handleSearch}
minLength={3}
value={values.pincode}
/>
{errors.pincode && touched.pincode && (<span className="form-error">{errors.pincode}</span>)}
id="basic-behaviors-example"
labelKey="name"
options={pincodeData && pincodeData.length>0 && pincodeData.map(item=>{
return {name: item.attributes.name, id: item.id}
})}
placeholder="Choose a state..."
ref={ref}
onBlur={() => {
console.log(ref.current);
if (!ref.current.state.selected.length > 0) {
ref.current?.clear();
}
}}
onChange={(e) => {
console.log("input change", e);
}}
/> */}
<input type="text" name="pincode" onChange={handleChange} onBlur={handleBlur} value={values.pincode} />
{errors.pincode && touched.pincode && <span className="form-error">{errors.pincode}</span>}
</div>
</div>
<div className="col-12 offset-lg-1 col-lg-5">
<div className="input-group">
<label>Country</label>
<select
id="country"
name="country"
onChange={handleChange}
onBlur={handleBlur}
>
<option value="India">India</option>
<option value="America">America</option>
</select>
{errors.country && touched.country && (<span className="form-error">{errors.country}</span>)}
<input type="text" name="country" onChange={handleChange} onBlur={handleBlur} value={values.country} />
{errors.country && touched.country && <span className="form-error">{errors.country}</span>}
</div>
</div>
</div>
......@@ -239,31 +256,15 @@ const BusinessDetails = () => {
<div className="col-12 col-lg-5">
<div className="input-group">
<label>State</label>
<select
id="state"
name="state"
onChange={handleChange}
onBlur={handleBlur}
>
<option value="India">India</option>
<option value="America">America</option>
</select>
{errors.state && touched.state && (<span className="form-error">{errors.state}</span>)}
<input type="text" name="state" onChange={handleChange} onBlur={handleBlur} value={values.state} />
{errors.state && touched.state && <span className="form-error">{errors.state}</span>}
</div>
</div>
<div className="col-12 offset-lg-1 col-lg-5">
<div className="input-group">
<label>City</label>
<select
id="city"
name="city"
onChange={handleChange}
onBlur={handleBlur}
>
<option value="India">India</option>
<option value="America">America</option>
</select>
{errors.city && touched.city && (<span className="form-error">{errors.city}</span>)}
<input type="text" name="city" onChange={handleChange} onBlur={handleBlur} value={values.city} />
{errors.city && touched.city && <span className="form-error">{errors.city}</span>}
</div>
</div>
</div>
......@@ -271,27 +272,15 @@ const BusinessDetails = () => {
<div className="col-12 col-lg-5">
<div className="input-group">
<label>Address Line 1</label>
<input
type="text"
name="addressLine1"
onChange={handleChange}
onBlur={handleBlur}
value={values.addressLine1}
/>
{errors.addressLine1 && touched.addressLine1 && (<span className="form-error">{errors.addressLine1}</span>)}
<input type="text" name="addressLine1" onChange={handleChange} onBlur={handleBlur} value={values.addressLine1} />
{errors.addressLine1 && touched.addressLine1 && <span className="form-error">{errors.addressLine1}</span>}
</div>
</div>
<div className="col-12 offset-lg-1 col-lg-5">
<div className="input-group">
<label>Address Line 2</label>
<input
type="text"
name="addressLine2"
onChange={handleChange}
onBlur={handleBlur}
value={values.addressLine2}
/>
{errors.addressLine2 && touched.addressLine2 && (<span className="form-error">{errors.addressLine2}</span>)}
<input type="text" name="addressLine2" onChange={handleChange} onBlur={handleBlur} value={values.addressLine2} />
{errors.addressLine2 && touched.addressLine2 && <span className="form-error">{errors.addressLine2}</span>}
</div>
</div>
</div>
......@@ -299,7 +288,7 @@ const BusinessDetails = () => {
<div className="row mt-3 mb-1">
<div className="col-12 col-lg-5">
<div className="input-group">
<Button type="submit" className="btn btn-primary btn-submit" disabled>
<Button type="submit" className="btn btn-primary btn-submit">
Send for Approval
</Button>
</div>
......@@ -340,8 +329,8 @@ const BusinessDetails = () => {
</div>
</div>
</div>
</Fragment >
)
}
</Fragment>
);
};
export default BusinessDetails;
......@@ -20,7 +20,7 @@
"qs": "^6.11.0",
"react": "18.2.0",
"react-bootstrap": "^2.5.0",
"react-bootstrap-typeahead": "^6.0.0",
"react-bootstrap-typeahead": "^6.3.2",
"react-datepicker": "^4.8.0",
"react-dom": "18.2.0",
"react-icons": "^5.0.1",
......
......@@ -37,15 +37,13 @@ export default NextAuth({
* We can expect it contains two properties: `email` and `password`
*/
try {
const {
data: { user, jwt }
} = await axios.post(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/auth/local`, {
const userResponse = await axios.post(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/auth/local`, {
identifier: email,
password: password
});
// console.log("Axios login returned with data:");
// console.log(user);
console.log("userResponse", userResponse.data);
// console.log(jwt);
// Response from the above call can be
......@@ -75,7 +73,7 @@ export default NextAuth({
// }
// }
return { ...user, name: user.username, jwt };
return { ...userResponse.data.user, name: userResponse.data.user.email, jwt: userResponse.data.jwt, email: userResponse.data.user.email, user: userResponse.data.user };
} catch (error) {
console.log("Error while fetching credentials:");
console.log(error.response.data);
......@@ -89,6 +87,8 @@ export default NextAuth({
],
callbacks: {
session: async ({ session, token }) => {
console.log("session 1", session);
console.log("session 2", token);
session.id = token.id;
session.jwt = token.jwt;
......@@ -98,6 +98,9 @@ export default NextAuth({
return Promise.resolve(session);
},
jwt: async ({ token, user }) => {
console.log("user 1", user);
console.log("token 1", token);
const isSignIn = user ? true : false;
if (isSignIn) {
token.id = user.id;
......
......@@ -35,11 +35,12 @@ export const registerUser = userData => async dispatch => {
};
const userFormData = new FormData();
userFormData.append("username", userData.mobile);
userFormData.append("username", `${userData.mobile}-${userData.email}`);
userFormData.append("email", userData.email);
userFormData.append("password", userData.password);
userFormData.append("role", userData.role);
userFormData.append("phone", userData.mobile);
console.log("userFormData", userFormData);
const response = await axios.post(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/auth/local/register`, userFormData, config);
console.log(`Register user done:`);
......
import axios from "axios";
import { getSession } from "next-auth/react";
import qs from "qs";
import {
GET_LOGGED_IN_VENDOR_FAIL,
GET_LOGGED_IN_VENDOR_REQUEST,
GET_LOGGED_IN_VENDOR_SUCCESS,
UPDATE_VENDOR_DETAILS_FAIL,
UPDATE_VENDOR_DETAILS_REQUEST,
UPDATE_VENDOR_DETAILS_SUCCESS
} from "../constants/vendorConstants";
export const finishVendorOtpVerification = async verificationData => {
const config = {
......@@ -9,3 +19,109 @@ export const finishVendorOtpVerification = async verificationData => {
return await axios.post(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/vendor/finish-otp-verification`, verificationData, config);
};
export const pincodeSearchByFilter = async code => {
const config = {
headers: {
"Content-Type": "application/json"
}
};
const query = {
filters: {
name: {
$contains: code
}
},
populate: ["masterCity"]
};
const queryString = qs.stringify(query, {
encodeValuesOnly: true
});
return await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/master-pincodes?${queryString}`, config);
};
export const updateVendorBusinessDetails =
({ businessDetails, vendorId }) =>
async dispatch => {
const session = await getSession();
if (!session) {
throw new Error("You are not authenticated. Please log in.");
}
try {
dispatch({
type: UPDATE_VENDOR_DETAILS_REQUEST
});
const config = {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${session.jwt}`
}
};
const response = await axios.put(
`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/vendors/${vendorId}`,
{
businessDetails
},
config
);
dispatch({
type: UPDATE_VENDOR_DETAILS_SUCCESS
});
} catch (error) {
dispatch({
type: UPDATE_VENDOR_DETAILS_FAIL
});
}
};
export const getLoggedInVendor = () => async dispatch => {
const session = await getSession();
console.log("session", session);
if (!session) {
throw new Error("You are not authenticated. Please log in.");
}
try {
dispatch({
type: GET_LOGGED_IN_VENDOR_REQUEST
});
const config = {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${session.jwt}`
}
};
const query = {
filters: {
user: {
$eq: session.id
}
}
};
const queryString = qs.stringify(query, {
encodeValuesOnly: true
});
const response = await axios.get(
`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/vendors/${queryString}`, config
);
console.log("response", response.data);
dispatch({
type: GET_LOGGED_IN_VENDOR_SUCCESS
});
} catch (error) {
dispatch({
type: GET_LOGGED_IN_VENDOR_FAIL
});
}
};
// export const FETCH_OTP_VERIFY_REQUEST = "FETCH_OTP_VERIFY_REQUEST"
// export const FETCH_OTP_VERIFY_SUCCESS = "FETCH_OTP_VERIFY_SUCCESS"
// export const FETCH_OTP_VERIFY_FAIL = "FETCH_OTP_VERIFY_FAIL"
export const GET_LOGGED_IN_VENDOR_REQUEST = "GET_LOGGED_IN_VENDOR_REQUEST"
export const GET_LOGGED_IN_VENDOR_SUCCESS = "GET_LOGGED_IN_VENDOR_SUCCESS"
export const GET_LOGGED_IN_VENDOR_FAIL = "GET_LOGGED_IN_VENDOR_FAIL"
// export const CLEAR_ERRORS = "CLEAR_ERRORS";
\ No newline at end of file
export const UPDATE_VENDOR_DETAILS_REQUEST = "UPDATE_VENDOR_DETAILS_REQUEST"
export const UPDATE_VENDOR_DETAILS_SUCCESS = "UPDATE_VENDOR_DETAILS_SUCCESS"
export const UPDATE_VENDOR_DETAILS_FAIL = "UPDATE_VENDOR_DETAILS_FAIL"
export const CLEAR_ERRORS = "CLEAR_ERRORS";
\ No newline at end of file
import { UPDATE_VENDOR_DETAILS_FAIL, UPDATE_VENDOR_DETAILS_REQUEST, UPDATE_VENDOR_DETAILS_SUCCESS, CLEAR_ERRORS } from "../constants/vendorConstants";
export const updateVendorReducer = (state = {}, action) => {
switch (action.type) {
case UPDATE_VENDOR_DETAILS_REQUEST:
return { loading: true };
case UPDATE_VENDOR_DETAILS_SUCCESS:
return {
loading: false,
updatedVendorData: action.payload
};
case UPDATE_VENDOR_DETAILS_FAIL:
return {
loading: false,
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
This diff could not be displayed because it is too large.
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!