Commit 2ae9d70a by jay

otp verification successful

1 parent 3c81ef95
Showing 51 changed files with 192 additions and 1629 deletions
import React, { useEffect, useRef, useState } from "react";
const OTPInput = ({ length = 4, onOtpSubmit = () => {}, otp, setOtp }) => {
const handleChange = (index, e) => {
const value = e.target.value;
if (isNaN(value)) return;
const newOtp = [...otp];
newOtp[index] = value.substring(value.length - 1);
setOtp(newOtp);
const combinedOtp = newOtp.join("");
if (combinedOtp.length === length) onOtpSubmit(combinedOtp);
if (value && index < length - 1 && inputRefs.current[index + 1]) {
inputRefs.current[index + 1].focus();
}
};
const handleClick = index => {
inputRefs.current[index].setSelectionRange(1, 1);
};
const handleKeyDown = (index, e) => {
if (e.key == "Backspace" && !otp[index] && index > 0 && inputRefs.current[index - 1]) {
inputRefs.current[index - 1].focus();
}
};
const inputRefs = useRef([]);
useEffect(() => {
if (inputRefs.current[0]) {
inputRefs.current[0].focus();
}
}, []);
// console.log("inputRefs", inputRefs);
return (
<div>
{otp.map((value, index) => {
return (
<input
key={index}
ref={input => (inputRefs.current[index] = input)}
type="text"
value={value}
onChange={e => {
handleChange(index, e);
}}
onClick={() => {
handleClick(index);
}}
onKeyDown={e => handleKeyDown(index, e)}
className="otpInput"
/>
);
})}
</div>
);
};
export default OTPInput;
import React, { useState } from "react"; import React, { useState, useRef } from "react";
import { Formik } from "formik"; import { Formik } from "formik";
import Link from "next/link"; import Link from "next/link";
import { Fragment } from "react"; import { Fragment } from "react";
import { Button, Form } from "react-bootstrap"; import { Button, Form } from "react-bootstrap";
import * as Yup from "yup"; import * as Yup from "yup";
import OTPInput from "react-otp-input";
import { renderImage } from "../../services/imageHandling"; import { renderImage } from "../../services/imageHandling";
import Image from "next/image"; import Image from "next/image";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import axios from "axios";
import { useDispatch } from "react-redux";
import { registerUser } from "../../redux/actions/userActions";
import { toast } from "react-toastify";
import OTPInput from "../common-components/OTPInput";
import { finishVendorOtpVerification } from "../../redux/actions/vendorActions";
const Signup = props => { const Signup = props => {
console.log(props.type); console.log(props.type);
const router = useRouter(); const router = useRouter();
const [Otp, setOtp] = useState(""); const [otp, setOtp] = useState(new Array(4).fill(""));
// const [isTermsChecked, setTermsChecked] = useState(false);
// const [fullName, setFullname] = useState("");
// const [emailId, setEmailId] = useState("");
// const [pwd, setPwd] = useState("")
// const [confirmPwd, setConfirmPwd] = useState("")
const [isOtpSent, setOtpSent] = useState(false); const [isOtpSent, setOtpSent] = useState(false);
const [otpVerified, setOtpVerified] = useState(false); const [otpVerified, setOtpVerified] = useState(false);
// const [passwordMatch, setPasswordMatch] = useState() const [loading, setLoading] = useState();
const handleOTPChange = e => { const dispatch = useDispatch();
setOtp(e);
const otpValue = useRef();
const changeOtpRef = value => {
console.log(otpValue);
if (otpValue.current?.length > 0) {
otpValue.current = [...otpValue.current, value];
} else {
otpValue.current = [value];
}
}; };
const signupValidationSchema = Yup.object().shape({ const signupValidationSchema = Yup.object().shape({
...@@ -83,51 +91,59 @@ const Signup = props => { ...@@ -83,51 +91,59 @@ const Signup = props => {
confirmPassword: "", confirmPassword: "",
countryCode: "", countryCode: "",
mobile: "", mobile: "",
termsConditions: false, termsConditions: false
otp: Otp ? Otp : "" // otp: Otp ? Otp : ""
}} }}
// initialErrors={initialErrors} // initialErrors={initialErrors}
validationSchema={signupValidationSchema} validationSchema={signupValidationSchema}
enableReinitialize={true} enableReinitialize={true}
onSubmit={values => { // onSubmit={e => {
console.log("signup values", values); // // e.preventDefault();
if (!isOtpSent) { // console.log("signup values", e);
handleSendOtp(values); // setOtpSent(true)
} // if (!isOtpSent) {
if (isOtpSent) { // // handleSendOtp(values);
handleVerifyOtp(values); // }
} // if (isOtpSent) {
}} // // handleVerifyOtp(values);
// }
// }}
> >
{({ values, errors, touched, handleChange, handleBlur, handleSubmit, isValid, isSubmitting }) => ( {({ values, errors, touched, handleChange, handleBlur, handleSubmit, isValid, isSubmitting }) => (
<Form <Form
onSubmit={e => { onSubmit={async e => {
if (!isOtpSent) {
setLoading(true);
e.preventDefault();
console.log("values", values);
const user = await dispatch(registerUser({ ...values, role: "vendor" }));
console.log("response", user);
if (user?.data?.status == "fail") {
toast.error(user?.data.message);
setLoading(false);
return;
}
setOtpSent(true);
} else {
e.preventDefault(); e.preventDefault();
handleSubmit(); const oneTimePassword = otp.join("")
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")
}
}
}} }}
> >
<div className="input-group"> <div className="input-group">
<label>Fullname</label> <label>Fullname</label>
<input <input type="text" name="fullname" onChange={handleChange} onBlur={handleBlur} value={values.fullname} placeholder="Your name" />
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>} {errors.fullname && touched.fullname && <span className="form-error">{errors.fullname}</span>}
</div> </div>
<div className="input-group"> <div className="input-group">
<label>Email Id</label> <label>Email Id</label>
<input <input type="text" name="email" onChange={handleChange} onBlur={handleBlur} value={values.email} placeholder="yourname@example.com" />
type="text"
name="email"
onChange={handleChange}
onBlur={handleBlur}
value={values.email}
placeholder="yourname@example.com"
/>
{errors.email && touched.email && <span className="form-error">{errors.email}</span>} {errors.email && touched.email && <span className="form-error">{errors.email}</span>}
</div> </div>
<div className="input-group"> <div className="input-group">
...@@ -175,6 +191,23 @@ const Signup = props => { ...@@ -175,6 +191,23 @@ const Signup = props => {
</div> </div>
{errors.mobile && touched.mobile && <span className="form-error">{errors.mobile}</span>} {errors.mobile && touched.mobile && <span className="form-error">{errors.mobile}</span>}
</div> </div>
<div className="input-group mb-3">
<label className="check-container mb-0 pt-1" htmlFor="termsConditions">
<input
type="checkbox"
id="termsConditions"
name="termsConditions"
className="check-box me-2"
checked={values.termsConditions}
onChange={handleChange}
onBlur={handleBlur}
/>
<span className="checkmark"></span>I Agree to the <Link href="">terms & conditions*</Link>
</label>
<br />
{errors.termsConditions && touched.termsConditions && <span className="form-error">{errors.termsConditions}</span>}
</div>
{isOtpSent && ( {isOtpSent && (
<> <>
<div className="input-group"> <div className="input-group">
...@@ -182,7 +215,7 @@ const Signup = props => { ...@@ -182,7 +215,7 @@ const Signup = props => {
OTP <span style={{ marginLeft: "190px" }}>00:30</span> OTP <span style={{ marginLeft: "190px" }}>00:30</span>
</label> </label>
<div className="otp-input"> <div className="otp-input">
<OTPInput value={Otp} onChange={handleOTPChange} numInputs={4} separator={<span> </span>} renderInput={props => <input {...props} />} /> <OTPInput setOtp={setOtp} otp={otp} />
</div> </div>
{errors.otp && touched.otp && <span className="form-error">{errors.otp}</span>} {errors.otp && touched.otp && <span className="form-error">{errors.otp}</span>}
</div> </div>
...@@ -200,26 +233,9 @@ const Signup = props => { ...@@ -200,26 +233,9 @@ const Signup = props => {
</div> </div>
</> </>
)} )}
<div className="input-group mb-3">
<label className="check-container mb-0 pt-1" htmlFor="termsConditions">
<input
type="checkbox"
id="termsConditions"
name="termsConditions"
className="check-box me-2"
checked={values.termsConditions}
onChange={handleChange}
onBlur={handleBlur}
/>
<span className="checkmark"></span>I Agree to the <Link href="">terms & conditions*</Link>
</label>
<br/>
{errors.termsConditions && touched.termsConditions && <span className="form-error">{errors.termsConditions}</span>}
</div>
<div className="input-group mb-0"> <div className="input-group mb-0">
<Button type="submit" className="btn btn-primary btn-submit" disabled={!values.termsConditions && !isValid}> <Button type="submit" className="btn btn-primary btn-submit" disabled={!values.termsConditions && !isValid}>
Sign Up Now {isOtpSent ? "Verify OTP" : "Sign Up Now"}
</Button> </Button>
</div> </div>
</Form> </Form>
...@@ -244,7 +260,7 @@ const Signup = props => { ...@@ -244,7 +260,7 @@ const Signup = props => {
<div className="form-container"> <div className="form-container">
<div className="input-group mb-2"> <div className="input-group mb-2">
<Button {/* <Button
type="button" type="button"
className="btn btn-primary btn-submit" className="btn btn-primary btn-submit"
// onClick={() => { // onClick={() => {
...@@ -252,7 +268,7 @@ const Signup = props => { ...@@ -252,7 +268,7 @@ const Signup = props => {
// }} // }}
> >
Proceed to Dashboard Proceed to Dashboard
</Button> </Button> */}
</div> </div>
</div> </div>
</div> </div>
......
import axios from "axios";
import { FETCH_BANKING_PARTNERS_SUCCESS, FETCH_BANKING_PARTNERS_FAIL, CLEAR_ERRORS } from "../constants/bankingPartnersConstants";
import qs from "qs";
// Get room details
export const getBankingPartners = () => async dispatch => {
try {
const config = {
headers: {
"Content-Type": "application/json"
}
};
const query = qs.stringify(
{
populate: ["logo"],
sort: ["serialNumber:desc"]
},
{
encodeValuesOnly: true // prettify URL
}
);
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/banking-partners?${query}`, config);
dispatch({
type: FETCH_BANKING_PARTNERS_SUCCESS,
payload: response.data
});
} catch (error) {
console.log("getBankingPartners:");
console.log(error.response.data);
dispatch({
type: FETCH_BANKING_PARTNERS_FAIL,
payload: error.response.data
});
}
};
// Clear errors
export const clearErrors = () => async dispatch => {
dispatch({
type: CLEAR_ERRORS
});
};
import axios from "axios";
import { BOOKING_DETAILS_SUCCESS, BOOKING_DETAILS_FAIL, FETCH_MY_BOOKINGS_SUCCESS, FETCH_MY_BOOKINGS_FAIL, CLEAR_ERRORS } from "../constants/bookingConstants";
import qs from "qs";
// Fetch room booked dates.
export const fetchMyBookings = session => async dispatch => {
// Note, when an action is going to be triggered on the server side, like this one is.
// then we cannot expect getSession() to give usa valid session, we need to instead use getSession({ req })
// and give it a req object instead.
// This action gets called from getServerSideProps on the me.js file.
// Hence here we have taken the session object from outside, instead of using getSession().
// Unlike a few other actions where we might have ended up using getSession directly, those actions like the loadUser & updateUser actions
// are all triggered on the UI using useEffect and from a submitHandler respectively.
if (!session) {
throw new Error("You are not authenticated currently. Only authenticated users can fetch their own bookings.");
}
try {
const config = {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${session.jwt}`
}
};
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/my-bookings`, config);
dispatch({
type: FETCH_MY_BOOKINGS_SUCCESS,
payload: response.data.bookings
});
} catch (error) {
dispatch({
type: FETCH_MY_BOOKINGS_FAIL,
payload: error.response.data
});
}
};
// Get room details
export const getBookingDetails = (bookingId, session) => async dispatch => {
// const session = await getSession();
if (!session) {
throw new Error("You are not authenticated currently. Only authenticated users can fetch their own bookings.");
}
try {
const config = {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${session.jwt}`
}
};
const query = qs.stringify(
{
populate: {
room: {
populate: ["images"]
},
user: {
populate: ["*"]
}
}
},
{
encodeValuesOnly: true // prettify URL
}
);
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/bookings/${bookingId}?${query}`, config);
dispatch({
type: BOOKING_DETAILS_SUCCESS,
payload: response.data
});
} catch (error) {
console.log("getBookingDetails:");
console.log(error.response.data);
dispatch({
type: BOOKING_DETAILS_FAIL,
payload: error.response.data
});
}
};
// Clear errors
export const clearErrors = () => async dispatch => {
dispatch({
type: CLEAR_ERRORS
});
};
import axios from "axios";
import { FETCH_COMPANY_INFORMATION_SUCCESS, FETCH_COMPANY_INFORMATION_FAIL, CLEAR_ERRORS } from "../constants/companyInformationConstants";
import qs from "qs";
// Get room details
export const getCompanyInformation = () => async dispatch => {
try {
const config = {
headers: {
"Content-Type": "application/json"
}
};
const query = qs.stringify(
{
populate: ["logo"]
},
{
encodeValuesOnly: true // prettify URL
}
);
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/company-information?${query}`, config);
dispatch({
type: FETCH_COMPANY_INFORMATION_SUCCESS,
payload: response.data
});
} catch (error) {
console.log("Error while fetching company information");
console.log(error);
// console.log(error.response.data);
dispatch({
type: FETCH_COMPANY_INFORMATION_FAIL,
payload: error.response.data
});
}
};
// Clear errors
export const clearErrors = () => async dispatch => {
dispatch({
type: CLEAR_ERRORS
});
};
import axios from "axios";
import { CLEAR_ERRORS, CONTACT_US_SUBMIT_FAIL, CONTACT_US_SUBMIT_REQUEST, CONTACT_US_SUBMIT_SUCCESS } from "../constants/contactUsConstants";
export const postContactUsDetails = contactUsData => async dispatch => {
try {
dispatch({
type: CONTACT_US_SUBMIT_REQUEST
});
const config = {
headers: {
"Content-Type": "application/json"
}
};
const response = await axios.post(
`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/leads`,
{
data: {
fullName: contactUsData?.fullName,
email: contactUsData?.emailAddress,
mobileNumber: contactUsData?.mobileNumber,
project: contactUsData?.projects,
comments: contactUsData?.comments
}
},
config
);
dispatch({
type: CONTACT_US_SUBMIT_SUCCESS,
payload: response.data
});
} catch (error) {
console.log("Error while submitting referral details: ");
console.log(error);
dispatch({
type: CONTACT_US_SUBMIT_FAIL,
payload: error.response.data
});
}
};
export const clearErrors = () => async dispatch => {
dispatch({
type: CLEAR_ERRORS
});
};
\ No newline at end of file \ No newline at end of file
import axios from "axios";
import { FETCH_CP_CONNECT_PAGE_SUCCESS, FETCH_CP_CONNECT_PAGE_FAIL, CLEAR_ERRORS } from "../constants/cpConnectPageConstants";
import qs from "qs";
// Get room details
export const getCPConnectPage = () => async dispatch => {
try {
const config = {
headers: {
"Content-Type": "application/json"
}
};
const query = qs.stringify(
{
populate: ["banner"]
},
{
encodeValuesOnly: true // prettify URL
}
);
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/cp-connect-page?${query}`, config);
dispatch({
type: FETCH_CP_CONNECT_PAGE_SUCCESS,
payload: response.data
});
} catch (error) {
console.log(error.response.data);
dispatch({
type: FETCH_CP_CONNECT_PAGE_FAIL,
payload: error.response.data
});
}
};
// Clear errors
export const clearErrors = () => async dispatch => {
dispatch({
type: CLEAR_ERRORS
});
};
import axios from "axios";
import { CLEAR_ERRORS } from "../constants/cpLoginConstants";
export const finishChannelPartnerOtpLogin = async ({ mobileNumber, mahareraNumber, oneTimePassword }) => {
// 1. invoke the api to start the login with otp process.
const config = {
headers: {
"Content-Type": "application/json"
}
};
return await axios.post(
`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/users-permissions/users/channel-partner/finish-otp-login`,
{
mobileNumber,
mahareraNumber,
oneTimePassword
},
config
);
};
export const startChannelPartnerOtpLogin = async ({ mobileNumber, mahareraNumber }) => {
// 1. invoke the api to start the login with otp process.
const config = {
headers: {
"Content-Type": "application/json"
}
};
const startOtpLoginResponse = await axios.post(
`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/users-permissions/users/channel-partner/start-otp-login`,
{
mobileNumber,
mahareraNumber
},
config
);
return startOtpLoginResponse;
};
// Clear errors
export const clearErrors = () => async dispatch => {
dispatch({
type: CLEAR_ERRORS
});
};
import { FETCH_DETAILS_FAIL, FETCH_DETAILS_SUCCESS, CLEAR_ERRORS } from "../constants/detailsConstants";
import axios from "axios";
import qs from "qs";
export const getDetails = detailsId => async dispatch => {
try {
const config = {
headers: {
"Content-Type": "application/json"
}
};
const query = qs.stringify(
{
populate: ["image"],
sort: ["serialNumber:desc"]
},
{
encodeValuesOnly: true // prettify URL
}
);
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/projects/${detailsId}?${query}`, config);
dispatch({
type: FETCH_DETAILS_SUCCESS,
payload: response.data
});
} catch (error) {
console.log("Error while fetching Project details: ");
console.log(error.response.data);
dispatch({
type: FETCH_DETAILS_FAIL,
payload: error.response.data
});
}
};
// Clear errors
export const clearErrors = () => async dispatch => {
dispatch({
type: CLEAR_ERRORS
});
};
import axios from "axios";
import { FETCH_HOME_BANNERS_SUCCESS, FETCH_HOME_BANNERS_FAIL, CLEAR_ERRORS } from "../constants/homeBannerConstants";
import qs from "qs";
// Get room details
export const getHomeBanners = () => async dispatch => {
try {
const config = {
headers: {
"Content-Type": "application/json"
}
};
const query = qs.stringify(
{
populate: ["image"],
sort: ["serialNumber:desc"]
},
{
encodeValuesOnly: true // prettify URL
}
);
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/home-banners?${query}`, config);
dispatch({
type: FETCH_HOME_BANNERS_SUCCESS,
payload: response.data
});
} catch (error) {
console.log("Error while fetching home banners: ");
console.log(error.response.data);
dispatch({
type: FETCH_HOME_BANNERS_FAIL,
payload: error.response.data
});
}
};
// Clear errors
export const clearErrors = () => async dispatch => {
dispatch({
type: CLEAR_ERRORS
});
};
import axios from "axios";
import { FETCH_HOME_CONTENT_SUCCESS, FETCH_HOME_CONTENT_FAIL, CLEAR_ERRORS } from "../constants/homeContentConstants";
import qs from "qs";
// Get room details
export const getHomeContent = () => async dispatch => {
try {
const config = {
headers: {
"Content-Type": "application/json"
}
};
const query = qs.stringify(
{
populate: ["image1", "image2", "image3"]
},
{
encodeValuesOnly: true // prettify URL
}
);
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/home-content?${query}`, config);
dispatch({
type: FETCH_HOME_CONTENT_SUCCESS,
payload: response.data
});
} catch (error) {
console.log("getHomeContent:");
console.log(error.response.data);
dispatch({
type: FETCH_HOME_CONTENT_FAIL,
payload: error.response.data
});
}
};
// Clear errors
export const clearErrors = () => async dispatch => {
dispatch({
type: CLEAR_ERRORS
});
};
import axios from "axios";
import { FETCH_HOME_DELIVERY_STATS_FAIL, FETCH_HOME_DELIVERY_STATS_SUCCESS, CLEAR_ERRORS } from "../constants/homeDeliveryStatsConstants";
import qs from "qs";
export const getHomeDeliveryStats = () => async dispatch => {
try {
const config = {
headers: {
"Content-Type": "application/json"
}
};
const query = qs.stringify(
{
populate: ["backgroundImage"]
},
{
encodeValuesOnly: true // prettify URL
}
);
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/delivery-stat?${query}`, config);
dispatch({
type: FETCH_HOME_DELIVERY_STATS_SUCCESS,
payload: response.data
});
} catch (error) {
console.log("Error while fetching delivery stats");
console.log(error.response.data);
dispatch({
type: FETCH_HOME_DELIVERY_STATS_FAIL,
payload: error.response.data
});
}
};
// Clear errors
export const clearErrors = () => async dispatch => {
dispatch({
type: CLEAR_ERRORS
});
};
import axios from "axios";
import { FETCH_LOCATIONS_SUCCESS, FETCH_LOCATIONS_FAIL, CLEAR_ERRORS } from "../constants/locationsConstants";
import qs from "qs";
// Get room details
export const getLocations = () => async dispatch => {
try {
const config = {
headers: {
"Content-Type": "application/json"
}
};
const query = qs.stringify(
{
filters: {},
populate: [],
pagination: {
pageSize: 100,
page: 1
}
},
{
encodeValuesOnly: true // prettify URL
}
);
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/locations?${query}`, config);
dispatch({
type: FETCH_LOCATIONS_SUCCESS,
payload: response.data
});
} catch (error) {
console.log("Error while locations: ");
console.log(error);
dispatch({
type: FETCH_LOCATIONS_FAIL,
payload: error.response.data
});
}
};
// Clear errors
export const clearErrors = () => async dispatch => {
dispatch({
type: CLEAR_ERRORS
});
};
import axios from "axios";
import qs from "qs";
import { FETCH_MENU_ITEMS_REQUEST, FETCH_MENU_ITEMS_SUCCESS, FETCH_MENU_ITEMS_FAIL, CLEAR_ERRORS } from "../constants/menuItemsConstants";
export const getMenuItems =
({ menu = "Main", published = true }) =>
async dispatch => {
const fmir = `${FETCH_MENU_ITEMS_REQUEST}_${menu.toUpperCase()}`;
const fmis = `${FETCH_MENU_ITEMS_SUCCESS}_${menu.toUpperCase()}`;
const fmif = `${FETCH_MENU_ITEMS_FAIL}_${menu.toUpperCase()}`;
const ce = `${CLEAR_ERRORS}_${menu.toUpperCase()}`;
try {
dispatch({
type: fmir
});
const itemsPerPage = 100;
const query = {
filters: {
menu: {
name: {
$eq: menu
}
}
},
populate: ["parent"],
pagination: {
pageSize: itemsPerPage,
page: 1
},
sort: ['serialNumber:asc'],
// fields: ['title'],
// publicationState: 'live',
// locale: ['en'],
publicationState: published ? "live" : "preview"
};
const queryString = qs.stringify(query, {
encodeValuesOnly: true
});
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/menu-items?${queryString}`);
dispatch({
type: fmis,
payload: response.data
});
} catch (error) {
console.log("Error while fetching menu items: ");
console.log(error.response.data);
dispatch({
type: fmif,
payload: error.response.data
});
}
};
import axios from "axios";
import { REFERRAL_SUBMIT_FAIL, REFERRAL_SUBMIT_REQUEST, REFERRAL_SUBMIT_SUCCESS, CLEAR_ERRORS } from "../constants/referralConstants";
export const postReferralDetails = referralData => async dispatch => {
try {
dispatch({
type: REFERRAL_SUBMIT_REQUEST
});
const config = {
headers: {
"Content-Type": "application/json"
}
};
const response = await axios.post(
`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/referrals`,
{
data: {
fullName: referralData.fullName,
township: referralData.township,
mobileNumber: referralData.mobileNo,
project: referralData.building,
email: referralData.email,
wing: referralData.wing,
flatNumber: referralData.flatNo,
ownershipType: referralData.ownershipType,
purchasedYear: referralData.purchasedYear,
purchasedSource: referralData.purchasedSource,
referralName: referralData.referralName,
referralPhoneNo: referralData.referralMobileNo,
referralEmail: referralData.referralEmail,
projectReferredTo: referralData.projectReferredTo
}
},
config
);
dispatch({
type: REFERRAL_SUBMIT_SUCCESS,
payload: response.data
});
} catch (error) {
console.log("Error while submitting referral details: ");
console.log(error);
dispatch({
type: REFERRAL_SUBMIT_FAIL,
payload: error.response.data
});
}
};
// Clear errors
export const clearErrors = () => async dispatch => {
dispatch({
type: CLEAR_ERRORS
});
};
import axios from "axios";
import qs from "qs";
import {
ROOM_CHECK_AVAILABILITY_REQUEST,
ROOM_CHECK_AVAILABILITY_SUCCESS,
ROOM_CHECK_AVAILABILITY_RESET,
ROOM_CHECK_AVAILABILITY_FAIL,
ROOM_MAKE_REVIEW_REQUEST,
ROOM_MAKE_REVIEW_SUCCESS,
ROOM_MAKE_REVIEW_RESET,
ROOM_MAKE_REVIEW_FAIL,
ROOM_FETCH_BOOKED_DATES_SUCCESS,
ROOM_FETCH_BOOKED_DATES_FAIL,
ALL_ROOMS_FAIL,
ALL_ROOMS_SUCCESS,
ROOM_DETAILS_SUCCESS,
ROOM_DETAILS_FAIL,
CLEAR_ERRORS
} from "../constants/roomConstants";
import { getSession } from "next-auth/react";
// Get all rooms
export const getRooms =
(currentPage = 1, location = "", guests, category) =>
async dispatch => {
try {
const roomsPerPage = 4;
const query = {
filters: {
address: {
$contains: location
}
},
populate: ["images"],
pagination: {
pageSize: roomsPerPage,
page: currentPage
}
// sort: ['title:asc'],
// fields: ['title'],
// publicationState: 'live',
// locale: ['en'],
};
// Add all the optional filters.
if (guests) query.filters["guestCapacity"] = { $eq: guests };
if (category) query.filters["category"] = { $eq: category };
const queryString = qs.stringify(query, {
encodeValuesOnly: true // prettify URL
});
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/rooms?${queryString}`);
dispatch({
type: ALL_ROOMS_SUCCESS,
payload: response.data
});
} catch (error) {
console.log("Real error is: ");
console.log(error);
dispatch({
type: ALL_ROOMS_FAIL,
payload: error.response.data
});
}
};
// Get room details
export const getRoomDetails = roomId => async dispatch => {
try {
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/rooms/${roomId}?populate[0]=images`);
dispatch({
type: ROOM_DETAILS_SUCCESS,
payload: response.data
});
} catch (error) {
dispatch({
type: ROOM_DETAILS_FAIL,
payload: error.response.data
});
}
};
// Check for room availability
export const checkRoomAvailability = (roomId, checkInDate, checkOutDate) => async dispatch => {
try {
dispatch({
type: ROOM_CHECK_AVAILABILITY_REQUEST
});
const response = await axios.get(
`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/rooms/check-availability?roomId=${roomId}&checkInDate=${checkInDate}&checkOutDate=${checkOutDate}`
);
dispatch({
type: ROOM_CHECK_AVAILABILITY_SUCCESS,
payload: response.data
});
} catch (error) {
// console.log("Error while check room availability");
// console.log(error);
dispatch({
type: ROOM_CHECK_AVAILABILITY_FAIL,
payload: error.response.data
});
}
};
// Fetch room booked dates.
export const fetchRoomBookedDates = roomId => async dispatch => {
try {
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/rooms/fetch-booked-dates?roomId=${roomId}`);
dispatch({
type: ROOM_FETCH_BOOKED_DATES_SUCCESS,
payload: response.data
});
} catch (error) {
dispatch({
type: ROOM_FETCH_BOOKED_DATES_FAIL,
payload: error.response.data
});
}
};
// update profile.
export const makeReview = reviewData => async dispatch => {
const session = await getSession();
if (!session) {
throw new Error("You need to be logged in before creating a review.");
}
try {
dispatch({
type: ROOM_MAKE_REVIEW_REQUEST
});
const config = {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${session.jwt}`
}
};
const response = await axios.post(
`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/rooms/reviews`,
{
rating: reviewData.rating,
comment: reviewData.comment,
roomId: reviewData.roomId
},
config
);
dispatch({
type: ROOM_MAKE_REVIEW_SUCCESS,
payload: response.data
});
} catch (error) {
console.log("Error while making a review: ");
console.log(error);
dispatch({
type: ROOM_MAKE_REVIEW_FAIL,
payload: error.response.data
});
}
};
// Clear errors
export const clearErrors = () => async dispatch => {
dispatch({
type: CLEAR_ERRORS
});
};
import axios from "axios";
import qs from "qs";
import {
FETCH_TOWNSHIPS_REQUEST,
FETCH_TOWNSHIPS_SUCCESS,
FETCH_TOWNSHIPS_FAIL,
FETCH_TOWNSHIP_REQUEST,
FETCH_TOWNSHIP_SUCCESS,
FETCH_TOWNSHIP_FAIL,
CLEAR_ERRORS
} from "../constants/townshipsConstants";
export const getTownships =
({ currentPage = 1, resultsPerPage = 3, published = true }) =>
async dispatch => {
try {
dispatch({
type: FETCH_TOWNSHIPS_REQUEST
});
const query = {
filters: {},
populate: ["townshipImages", "townshipImages.image", "location"],
pagination: {
pageSize: resultsPerPage,
page: currentPage
},
publicationState: published ? "live" : "preview"
};
const queryString = qs.stringify(query, {
encodeValuesOnly: true
});
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/townships?${queryString}`);
dispatch({
type: FETCH_TOWNSHIPS_SUCCESS,
payload: response.data
});
} catch (error) {
console.log("Real error is: ");
console.log(error.response.data);
dispatch({
type: FETCH_TOWNSHIPS_FAIL,
payload: error.response.data
});
}
};
export const getTownship = townshipId => async dispatch => {
try {
dispatch({
type: FETCH_TOWNSHIP_REQUEST
});
const query = {
// filters: {},
populate: ["townshipImages", "townshipImages.image", "location","cpGuidelines"]
// pagination: {
// pageSize: resultsPerPage,
// page: currentPage
// },
// publicationState: published ? "live" : "preview"
};
const queryString = qs.stringify(query, {
encodeValuesOnly: true
});
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/townships/${townshipId}?${queryString}`);
dispatch({
type: FETCH_TOWNSHIP_SUCCESS,
payload: response.data
});
} catch (error) {
console.log("Real error is: ");
// console.log(error.response.data);
console.log(error);
dispatch({
type: FETCH_TOWNSHIP_FAIL,
payload: error.response.data
});
}
};
...@@ -35,7 +35,7 @@ export const registerUser = userData => async dispatch => { ...@@ -35,7 +35,7 @@ export const registerUser = userData => async dispatch => {
}; };
const userFormData = new FormData(); const userFormData = new FormData();
userFormData.append("username", userData.username); userFormData.append("username", userData.mobile);
userFormData.append("email", userData.email); userFormData.append("email", userData.email);
userFormData.append("password", userData.password); userFormData.append("password", userData.password);
userFormData.append("role", userData.role); userFormData.append("role", userData.role);
...@@ -45,17 +45,23 @@ export const registerUser = userData => async dispatch => { ...@@ -45,17 +45,23 @@ export const registerUser = userData => async dispatch => {
console.log(`Register user done:`); console.log(`Register user done:`);
console.log(response); console.log(response);
if (response?.data?.status == "fail") {
return response;
}
// Immediately after user creation based on the role of the user we need to create entry into the corresponding extension table. // Immediately after user creation based on the role of the user we need to create entry into the corresponding extension table.
// Do for End user
if (userData.role === "Channel Partner") { if (userData.role === "Channel Partner") {
userData["userId"] = response.data.user.id; userData["userId"] = response.data.user.id;
await registerChannelPartner(userData); await registerChannelPartner(userData);
} }
if (userData.role === "End User") { if (userData.role === "vendor") {
userData["userId"] = response.data.user.id; console.log("userdata", userData);
await registerEndUser(userData); // userData["userId"] = response.data.user.id;
await registerVendor({ ...userData, userId: response.data.user.id });
} }
console.log(`About to dispatch REGISTER_USER_SUCCESS`); // console.log(`About to dispatch REGISTER_USER_SUCCESS`);
dispatch({ dispatch({
type: REGISTER_USER_SUCCESS type: REGISTER_USER_SUCCESS
}); });
...@@ -70,6 +76,32 @@ export const registerUser = userData => async dispatch => { ...@@ -70,6 +76,32 @@ export const registerUser = userData => async dispatch => {
} }
}; };
const registerVendor = async vendorData => {
const authUser = await axios.post(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/auth/local`, {
identifier: vendorData.email,
password: vendorData.password
});
console.log("jwt", authUser);
const config = {
headers: {
Authorization: `Bearer ${authUser.data.jwt}`,
"Content-Type": "application/json"
}
};
const data = {
data: {
mobileNo: vendorData.mobile,
name: vendorData.fullname,
email: vendorData.email,
user: authUser.data.user.id
}
};
const response = await axios.post(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/vendors`, data, config);
return response;
};
// register a new user. // register a new user.
export const loadUser = () => async dispatch => { export const loadUser = () => async dispatch => {
const session = await getSession(); const session = await getSession();
......
import axios from "axios";
export const finishVendorOtpVerification = async verificationData => {
const config = {
headers: {
"Content-Type": "application/json"
}
};
return await axios.post(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/vendor/finish-otp-verification`, verificationData, config);
};
export const FETCH_BANKING_PARTNERS_SUCCESS = "FETCH_BANKING_PARTNERS_SUCCESS";
export const FETCH_BANKING_PARTNERS_FAIL = "FETCH_BANKING_PARTNERS_FAIL";
export const CLEAR_ERRORS = "CLEAR_ERRORS";
export const FETCH_MY_BOOKINGS_SUCCESS = "FETCH_MY_BOOKINGS_SUCCESS";
export const FETCH_MY_BOOKINGS_FAIL = "FETCH_MY_BOOKINGS_FAIL";
export const BOOKING_DETAILS_SUCCESS = "BOOKING_DETAILS_SUCCESS";
export const BOOKING_DETAILS_FAIL = "BOOKING_DETAILS_FAIL";
export const CLEAR_ERRORS = "CLEAR_ERRORS";
export const FETCH_COMPANY_INFORMATION_SUCCESS = "FETCH_COMPANY_INFORMATION_SUCCESS";
export const FETCH_COMPANY_INFORMATION_FAIL = "FETCH_COMPANY_INFORMATION_FAIL";
export const CLEAR_ERRORS = "CLEAR_ERRORS";
export const CONTACT_US_SUBMIT_REQUEST = "CONTACT_US_SUBMIT_REQUEST";
export const CONTACT_US_SUBMIT_SUCCESS = "CONTACT_US_SUBMIT_SUCCESS";
export const CONTACT_US_SUBMIT_FAIL = "CONTACT_US_SUBMIT_FAIL";
export const CLEAR_ERRORS = "CLEAR_ERRORS";
export const FETCH_CP_CONNECT_PAGE_SUCCESS = "FETCH_CP_CONNECT_PAGE_SUCCESS";
export const FETCH_CP_CONNECT_PAGE_FAIL = "FETCH_CP_CONNECT_PAGE_FAIL";
export const CLEAR_ERRORS = "CLEAR_ERRORS";
export const LOGIN_SUCCESS = "LOGIN_SUCCESS";
export const LOGIN_FAIL = "LOGIN_FAIL";
export const CLEAR_ERRORS = "CLEAR_ERRORS";
export const FETCH_DETAILS_SUCCESS = "FETCH_CP_CONNECT_PAGE_SUCCESS";
export const FETCH_DETAILS_FAIL = "FETCH_CP_CONNECT_PAGE_FAIL";
export const CLEAR_ERRORS = "CLEAR_ERRORS";
export const FETCH_HOME_BANNERS_SUCCESS = "FETCH_HOME_BANNERS_SUCCESS";
export const FETCH_HOME_BANNERS_FAIL = "FETCH_HOME_BANNERS_FAIL";
export const CLEAR_ERRORS = "CLEAR_ERRORS";
export const FETCH_HOME_CONTENT_SUCCESS = "FETCH_HOME_CONTENT_SUCCESS";
export const FETCH_HOME_CONTENT_FAIL = "FETCH_HOME_CONTENT_FAIL";
export const CLEAR_ERRORS = "CLEAR_ERRORS";
export const FETCH_HOME_DELIVERY_STATS_SUCCESS = "FETCH_HOME_DELIVERY_STATS_SUCCESS";
export const FETCH_HOME_DELIVERY_STATS_FAIL = "FETCH_HOME_DELIVERY_STATS_FAIL";
export const CLEAR_ERRORS = "CLEAR_ERRORS";
export const FETCH_LOCATIONS_SUCCESS = "FETCH_LOCATIONS_SUCCESS";
export const FETCH_LOCATIONS_FAIL = "FETCH_LOCATIONS_FAIL";
export const CLEAR_ERRORS = "CLEAR_ERRORS";
export const FETCH_MENU_ITEMS_REQUEST = "FETCH_MENU_ITEMS_REQUEST";
export const FETCH_MENU_ITEMS_SUCCESS = "FETCH_MENU_ITEMS_SUCCESS";
export const FETCH_MENU_ITEMS_FAIL = "FETCH_MENU_ITEMS_FAIL";
export const CLEAR_ERRORS = "CLEAR_ERRORS";
export const REFERRAL_SUBMIT_REQUEST = "REFERRAL_SUBMIT_REQUEST";
export const REFERRAL_SUBMIT_SUCCESS = "REFERRAL_SUBMIT_SUCCESS";
export const REFERRAL_SUBMIT_FAIL = "REFERRAL_SUBMIT_FAIL";
export const CLEAR_ERRORS = "CLEAR_ERRORS";
export const ALL_ROOMS_SUCCESS = "ALL_ROOMS_SUCCESS";
export const ALL_ROOMS_FAIL = "ALL_ROOMS_FAIL";
export const ROOM_DETAILS_SUCCESS = "ROOM_DETAILS_SUCCESS";
export const ROOM_DETAILS_FAIL = "ROOM_DETAILS_FAIL";
export const ROOM_CHECK_AVAILABILITY_REQUEST = "ROOM_CHECK_AVAILABILITY_REQUEST";
export const ROOM_CHECK_AVAILABILITY_SUCCESS = "ROOM_CHECK_AVAILABILITY_SUCCESS";
export const ROOM_CHECK_AVAILABILITY_RESET = "ROOM_CHECK_AVAILABILITY_RESET";
export const ROOM_CHECK_AVAILABILITY_FAIL = "ROOM_CHECK_AVAILABILITY_FAIL";
export const ROOM_MAKE_REVIEW_REQUEST = "ROOM_MAKE_REVIEW_REQUEST";
export const ROOM_MAKE_REVIEW_SUCCESS = "ROOM_MAKE_REVIEW_SUCCESS";
export const ROOM_MAKE_REVIEW_RESET = "ROOM_MAKE_REVIEW_RESET";
export const ROOM_MAKE_REVIEW_FAIL = "ROOM_MAKE_REVIEW_FAIL";
export const ROOM_FETCH_BOOKED_DATES_SUCCESS = "ROOM_FETCH_BOOKED_DATES_SUCCESS";
export const ROOM_FETCH_BOOKED_DATES_FAIL = "ROOM_FETCH_BOOKED_DATES_FAIL";
export const CLEAR_ERRORS = "CLEAR_ERRORS";
// 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 CLEAR_ERRORS = "CLEAR_ERRORS";
\ No newline at end of file \ No newline at end of file
import { FETCH_BANKING_PARTNERS_SUCCESS, FETCH_BANKING_PARTNERS_FAIL, CLEAR_ERRORS } from "../constants/bankingPartnersConstants";
// Room details reducer.
export const bankingPartnersReducer = (state = { bankingPartners: [] }, action) => {
switch (action.type) {
case FETCH_BANKING_PARTNERS_SUCCESS:
return {
bankingPartners: action.payload.data
};
case FETCH_BANKING_PARTNERS_FAIL:
return {
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
import { BOOKING_DETAILS_SUCCESS, BOOKING_DETAILS_FAIL, FETCH_MY_BOOKINGS_SUCCESS, FETCH_MY_BOOKINGS_FAIL, CLEAR_ERRORS } from "../constants/bookingConstants";
// Get all booked dates.
export const fetchMyBookingsReducer = (state = { bookings: [] }, action) => {
switch (action.type) {
case FETCH_MY_BOOKINGS_SUCCESS:
return {
loading: false,
bookings: action.payload
};
case FETCH_MY_BOOKINGS_FAIL:
return {
loading: false,
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
// Room details reducer.
export const bookingDetailsReducer = (state = { booking: {} }, action) => {
switch (action.type) {
case BOOKING_DETAILS_SUCCESS:
return {
booking: action.payload.data
};
case BOOKING_DETAILS_FAIL:
return {
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
import { FETCH_COMPANY_INFORMATION_SUCCESS, FETCH_COMPANY_INFORMATION_FAIL, CLEAR_ERRORS } from "../constants/companyInformationConstants";
// Room details reducer.
export const companyInformationReducer = (state = { companyInformation: {} }, action) => {
switch (action.type) {
case FETCH_COMPANY_INFORMATION_SUCCESS:
return {
companyInformation: action.payload.data
};
case FETCH_COMPANY_INFORMATION_FAIL:
return {
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
import { CONTACT_US_SUBMIT_FAIL, CONTACT_US_SUBMIT_REQUEST, CONTACT_US_SUBMIT_SUCCESS } from "../constants/contactUsConstants";
export const contactUsReducer = (state = { contactUs: null }, action) => {
switch (action.type) {
case CONTACT_US_SUBMIT_REQUEST:
return {
loading: true,
success: false
};
case CONTACT_US_SUBMIT_SUCCESS:
return {
loading: false,
success: true,
referral: action.payload
};
case CONTACT_US_SUBMIT_FAIL:
return {
loading: false,
success: false,
error: action.payload.error.message
};
default:
return state;
}
};
import { FETCH_CP_CONNECT_PAGE_SUCCESS, FETCH_CP_CONNECT_PAGE_FAIL, CLEAR_ERRORS } from "../constants/cpConnectPageConstants";
// Room details reducer.
export const cpConnectPageReducer = (state = { cpConnectPage: {} }, action) => {
switch (action.type) {
case FETCH_CP_CONNECT_PAGE_SUCCESS:
return {
cpConnectPage: action.payload.data
};
case FETCH_CP_CONNECT_PAGE_FAIL:
return {
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
import { LOGIN_SUCCESS, LOGIN_FAIL, CLEAR_ERRORS } from "../constants/cpLoginConstants";
// Room details reducer.
export const cpLoginReducer = (state = { cpLogin: {} }, action) => {
switch (action.type) {
case LOGIN_SUCCESS:
return {
cpLogin: action.payload.data
};
case LOGIN_FAIL:
return {
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
import { FETCH_DETAILS_FAIL, FETCH_DETAILS_SUCCESS, CLEAR_ERRORS } from "../constants/detailsConstants";
export const detailReducer = (state = { details: [] }, action) => {
switch (action.type) {
case FETCH_DETAILS_SUCCESS:
return {
details: action.payload.data
};
case FETCH_DETAILS_FAIL:
return {
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
import { FETCH_HOME_BANNERS_SUCCESS, FETCH_HOME_BANNERS_FAIL, CLEAR_ERRORS } from "../constants/homeBannerConstants";
// Room details reducer.
export const homeBannerReducer = (state = { homeBanners: [] }, action) => {
switch (action.type) {
case FETCH_HOME_BANNERS_SUCCESS:
return {
homeBanners: action.payload.data
};
case FETCH_HOME_BANNERS_FAIL:
return {
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
import { FETCH_HOME_CONTENT_SUCCESS, FETCH_HOME_CONTENT_FAIL, CLEAR_ERRORS } from "../constants/homeContentConstants";
// Room details reducer.
export const homeContentReducer = (state = { homeContent: {} }, action) => {
switch (action.type) {
case FETCH_HOME_CONTENT_SUCCESS:
return {
homeContent: action.payload.data
};
case FETCH_HOME_CONTENT_FAIL:
return {
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
import { CLEAR_ERRORS } from "../constants/homeDeliveryStatsConstants";
import { FETCH_HOME_DELIVERY_STATS_FAIL, FETCH_HOME_DELIVERY_STATS_SUCCESS } from "../constants/homeDeliveryStatsConstants";
export const homeDeliveryStatReducer = (state = { homeDeliveryStats: {} }, action) => {
switch (action.type) {
case FETCH_HOME_DELIVERY_STATS_SUCCESS:
return {
homeDeliveryStats: action.payload.data
};
case FETCH_HOME_DELIVERY_STATS_FAIL:
return {
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
import { FETCH_LOCATIONS_SUCCESS, FETCH_LOCATIONS_FAIL, CLEAR_ERRORS } from "../constants/locationsConstants";
// Room details reducer.
export const locationsReducer = (state = { locations: [] }, action) => {
switch (action.type) {
case FETCH_LOCATIONS_SUCCESS:
return {
locations: action.payload.data
};
case FETCH_LOCATIONS_FAIL:
return {
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
import { FETCH_MENU_ITEMS_REQUEST, FETCH_MENU_ITEMS_SUCCESS, FETCH_MENU_ITEMS_FAIL, CLEAR_ERRORS } from "../constants/menuItemsConstants";
// Room details reducer.
export const menuItemsReducer =
menu =>
(state = { menuItems: [] }, action) => {
const fmir = `${FETCH_MENU_ITEMS_REQUEST}_${menu.toUpperCase()}`;
const fmis = `${FETCH_MENU_ITEMS_SUCCESS}_${menu.toUpperCase()}`;
const fmif = `${FETCH_MENU_ITEMS_FAIL}_${menu.toUpperCase()}`;
const ce = `${CLEAR_ERRORS}_${menu.toUpperCase()}`;
switch (action.type) {
case fmir:
return {
loading: true
};
case fmis:
return {
loading: false,
totalCount: action.payload.meta.pagination.total,
resultsPerPage: action.payload.meta.pagination.pageSize,
menuItems: action.payload.data
};
case fmif:
return {
error: action.payload.error.message
};
case ce:
return {
...state,
error: null
};
default:
return state;
}
};
import { combineReducers } from "redux"; import { combineReducers } from "redux";
import { bankingPartnersReducer } from "./bankingPartnersReducer";
import { companyInformationReducer } from "./companyInformationReducer";
import { cpConnectPageReducer } from "./cpConnectPageReducer";
import { detailReducer } from "./detailsReducer";
import { cpLoginReducer } from "./cpLoginReducer";
import { homeBannerReducer } from "./homeBannersReducer";
import { homeContentReducer } from "./homeContentReducer";
import { homeDeliveryStatReducer } from "./homeDeliveryStatsReducer";
import { locationsReducer } from "./locationsReducer";
import { menuItemsReducer } from "./menuItemsReducer";
import { projectReducer, projectsReducer, similarProjectsReducer } from "./projectsReducer"; import { projectReducer, projectsReducer, similarProjectsReducer } from "./projectsReducer";
import { townshipReducer, townshipsReducer } from "./townshipsReducer"; import { townshipReducer, townshipsReducer } from "./townshipsReducer";
import { authReducer, forgotPasswordReducer, loadedUserReducer, resetPasswordReducer, userReducer } from "./userReducers"; import { authReducer, forgotPasswordReducer, loadedUserReducer, resetPasswordReducer, userReducer } from "./userReducers";
import { referralReducer } from "./referralReducer";
import { contactUsReducer } from "./contactUsReducer";
import { enquiryReducer } from "./enquiryReducer"; import { enquiryReducer } from "./enquiryReducer";
import { displayEnquireNowReducer } from "./enquireNowModalReducer"; import { displayEnquireNowReducer } from "./enquireNowModalReducer";
const reducers = combineReducers({ const reducers = combineReducers({
bankingPartners: bankingPartnersReducer,
homeContent: homeContentReducer,
homeBanners: homeBannerReducer,
townships: townshipsReducer, townships: townshipsReducer,
township: townshipReducer, township: townshipReducer,
projects: projectsReducer, projects: projectsReducer,
project: projectReducer, project: projectReducer,
companyInformation: companyInformationReducer,
mainMenuItems: menuItemsReducer("Main"),
footerMenuItems: menuItemsReducer("Footer"),
locations: locationsReducer,
homeDeliveryStats: homeDeliveryStatReducer,
cpConnectPage: cpConnectPageReducer,
auth: authReducer, auth: authReducer,
loadedUser: loadedUserReducer, loadedUser: loadedUserReducer,
user: userReducer, user: userReducer,
forgotPassword: forgotPasswordReducer, forgotPassword: forgotPasswordReducer,
resetPassword: resetPasswordReducer, resetPassword: resetPasswordReducer,
details: detailReducer,
cpLogin: cpLoginReducer,
referral: referralReducer,
similarProjects: similarProjectsReducer, similarProjects: similarProjectsReducer,
contactUs: contactUsReducer,
enquiry: enquiryReducer, enquiry: enquiryReducer,
displayEnquireNow:displayEnquireNowReducer displayEnquireNow:displayEnquireNowReducer
}); });
......
import { REFERRAL_SUBMIT_FAIL, REFERRAL_SUBMIT_REQUEST, REFERRAL_SUBMIT_SUCCESS } from "../constants/referralConstants";
export const referralReducer = (state = { referral: null }, action) => {
switch (action.type) {
case REFERRAL_SUBMIT_REQUEST:
return {
loading: true,
success: false
};
case REFERRAL_SUBMIT_SUCCESS:
return {
loading: false,
success: true,
referral: action.payload
};
case REFERRAL_SUBMIT_FAIL:
return {
loading: false,
success: false,
error: action.payload.error.message
};
default:
return state;
}
};
import {
ROOM_CHECK_AVAILABILITY_REQUEST,
ROOM_CHECK_AVAILABILITY_SUCCESS,
ROOM_CHECK_AVAILABILITY_RESET,
ROOM_CHECK_AVAILABILITY_FAIL,
ROOM_MAKE_REVIEW_REQUEST,
ROOM_MAKE_REVIEW_SUCCESS,
ROOM_MAKE_REVIEW_RESET,
ROOM_MAKE_REVIEW_FAIL,
ROOM_FETCH_BOOKED_DATES_SUCCESS,
ROOM_FETCH_BOOKED_DATES_FAIL,
ALL_ROOMS_FAIL,
ALL_ROOMS_SUCCESS,
ROOM_DETAILS_SUCCESS,
ROOM_DETAILS_FAIL,
CLEAR_ERRORS
} from "../constants/roomConstants";
// All rooms reducer.
export const allRoomsReducer = (state = { rooms: [] }, action) => {
switch (action.type) {
case ALL_ROOMS_SUCCESS:
return {
roomsCount: action.payload.meta.pagination.total,
resultsPerPage: action.payload.meta.pagination.pageSize,
filteredRoomsCount: 0,
rooms: action.payload.data
};
case ALL_ROOMS_FAIL:
return {
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
// Room details reducer.
export const roomDetailsReducer = (state = { room: {} }, action) => {
switch (action.type) {
case ROOM_DETAILS_SUCCESS:
return {
room: action.payload.data
};
case ROOM_DETAILS_FAIL:
return {
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
// room availability
export const checkRoomAvailabilityReducer = (state = { available: true }, action) => {
switch (action.type) {
case ROOM_CHECK_AVAILABILITY_REQUEST:
return {
loading: true
};
case ROOM_CHECK_AVAILABILITY_SUCCESS:
return {
loading: false,
available: action.payload.isAvailable
};
case ROOM_CHECK_AVAILABILITY_RESET:
return {
loading: false,
available: null
};
case ROOM_CHECK_AVAILABILITY_FAIL:
return {
loading: false,
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
// room availability
export const makeReviewReducer = (state = { review: null }, action) => {
switch (action.type) {
case ROOM_MAKE_REVIEW_REQUEST:
return {
loading: true
};
case ROOM_MAKE_REVIEW_SUCCESS:
return {
loading: false,
review: action.payload.review
};
case ROOM_MAKE_REVIEW_RESET:
return {
review: null
};
case ROOM_MAKE_REVIEW_FAIL:
return {
loading: false,
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
// Get all booked dates.
export const fetchRoomBookedDatesReducer = (state = { bookedDates: [] }, action) => {
switch (action.type) {
case ROOM_FETCH_BOOKED_DATES_SUCCESS:
return {
loading: false,
bookedDates: action.payload.bookedDates.map(bookedDate => new Date(bookedDate))
};
case ROOM_FETCH_BOOKED_DATES_FAIL:
return {
loading: false,
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
...@@ -26,7 +26,7 @@ export const renderImage = imagePath => { ...@@ -26,7 +26,7 @@ export const renderImage = imagePath => {
/** If now S3, then images are stored under the public/uploads directory of Strapi */ /** If now S3, then images are stored under the public/uploads directory of Strapi */
imageUrl = `${process.env.NEXT_PUBLIC_IMAGE_URL}${imagePath}`; imageUrl = `${process.env.NEXT_PUBLIC_IMAGE_URL}${imagePath}`;
} else { } else {
imageUrl = `http://localhost:3000${imagePath}`; imageUrl = `http://localhost:3015${imagePath}`;
} }
} }
return imageUrl; return imageUrl;
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!