From eda8686a994e15721e87409b6ca3fe8a28dde82d Mon Sep 17 00:00:00 2001 From: pawan-dot <71133473+pawan-dot@users.noreply.github.com> Date: Mon, 27 Mar 2023 17:46:26 +0530 Subject: [PATCH] business added and send email --- src/index.js | 1 + src/views/Business/AddBusiness.js | 68 +++- src/views/Business/multiform/Contacts.js | 309 ++++++++++++++++++ .../Business/multiform/selectLanguage.js | 4 +- 4 files changed, 375 insertions(+), 7 deletions(-) create mode 100644 src/views/Business/multiform/Contacts.js diff --git a/src/index.js b/src/index.js index ca62455..a43b94d 100644 --- a/src/index.js +++ b/src/index.js @@ -9,6 +9,7 @@ import * as serviceWorker from './serviceWorker' import { Provider } from 'react-redux' import axios from 'axios' import { store } from './redux/store'; +import { cibGmail } from '@coreui/icons'; const setupAxios = () => { axios.defaults.baseURL = 'https://bolo-api.checkapp.one/' diff --git a/src/views/Business/AddBusiness.js b/src/views/Business/AddBusiness.js index d4927f6..de8bbf0 100644 --- a/src/views/Business/AddBusiness.js +++ b/src/views/Business/AddBusiness.js @@ -7,6 +7,7 @@ import { CCard, CCardBody, CCardGroup, CCol, CContainer, CRow } from '@coreui/re import SelectPurpose from './multiform/SelectPurpose.js' import SelectBusiness from './multiform/SelectBusiness.js' import SelectLanguage from './multiform/selectLanguage.js' +import Contacts from './multiform/Contacts.js' import BAddress from './multiform/BAddress.js' import Button from '@material-ui/core/Button' @@ -18,12 +19,14 @@ const AddBusiness = () => { const token = isAutheticated() const [productId, setProductId] = useState('') const [viewState, setViewState] = useState(1) + // const [WebsiteURL, setWebsiteURL] = useState('https://bolo.ai.in/') const navigate = useNavigate() const [loading, setLoading] = useState(false) const [data, setData] = useState({ + WebsiteURL: 'https://bolo.ai.in/', business: '', purpose: '', @@ -33,7 +36,16 @@ const AddBusiness = () => { city: '', address_Line_1: '', address_Line_2: '', - pincode: '' + pincode: '', + //contacts + image: '', + imageURL: '', + business_name: '', + email: '', + + short_url: '', + contact_Number: '', + contact_Person_Name: '', }) @@ -55,7 +67,17 @@ const AddBusiness = () => { data.country === '' || data.state === '' || data.city === '' || - data.pincode.trim() === '' + data.pincode.trim() === '' || + //Contacts + // data.image === '' || + // data.imageURL.trim() === '' || + data.business_name.trim() === '' || + data.email.trim() === '' || + + data.short_url.trim() === '' || + data.contact_Number === '' || + data.contact_Person_Name.trim() === '' + ) { swal({ title: 'Warning', @@ -81,6 +103,17 @@ const AddBusiness = () => { formData.set('pincode', data.pincode) + //contacts + formData.set('business_name', data.business_name) + formData.set('email', data.email) + + + formData.set('contact_Number', data.contact_Number) + formData.set('contact_Person_Name', data.contact_Person_Name) + + + formData.set('url', data.WebsiteURL + data.short_url + '/login') + formData.set('short_url', data.short_url) axios .post(`/api/businesses/add`, formData, { @@ -151,7 +184,13 @@ const AddBusiness = () => { data.country === '' || data.state === '' || data.city === '' || - data.pincode.trim() === ''} + data.pincode.trim() === '' || + data.business_name.trim() === '' || + data.email.trim() === '' || + + data.short_url.trim() === '' || + data.contact_Number === '' || + data.contact_Person_Name.trim() === ''} > {loading ? 'Loading' : 'Add Now'} @@ -186,7 +225,19 @@ const AddBusiness = () => { loading={{ loading, setLoading }} /> )} + + + {viewState === 3 && ( + + )} + {viewState === 4 && ( { loading={{ loading, setLoading }} /> )} - {viewState === 4 && ( + {viewState === 5 && ( { type="button" onClick={() => handleView(3)} > - Select Languages + Contacts + diff --git a/src/views/Business/multiform/Contacts.js b/src/views/Business/multiform/Contacts.js new file mode 100644 index 0000000..869d482 --- /dev/null +++ b/src/views/Business/multiform/Contacts.js @@ -0,0 +1,309 @@ + + + +import React, { useEffect, useState } from 'react' +import Button from '@material-ui/core/Button' +import { Link, useNavigate } from 'react-router-dom' +import swal from 'sweetalert' +import axios from 'axios' +import { isAutheticated } from 'src/auth' +// import { WebsiteURL } from '../WebsiteURL' + +const Contacts = (props) => { + const token = isAutheticated() + + const navigate = useNavigate() + + const { data, setData } = props.data + + const { loading, setLoading } = props.loading + // const [data, setData] = useState({ + // image: '', + // imageURL: '', + // name: '', + // email: '', + + // short_url: '', + // contact_Number: '', + // contact_Person_Name: '', + + // }) + + + + const [validForm, setValidForm] = useState(false) + + + + + const [errors, setErrors] = useState({ + emailError: '', + phoneError: '' + + + }) + const validEmailRegex = RegExp( + /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i, + ) + const validPhoneRegex = RegExp( + /^(\+\d{1,2}\s?)?1?\-?\.?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/, + ) + + + const validateForm = () => { + let valid = true + Object.values(errors).forEach((val) => { + if (val.length > 0) { + valid = false + return false + } + }) + Object.values(data.email).forEach((val) => { + if (val.length <= 0) { + valid = false + return false + } + }) + return valid + } + + //cheking email and password + useEffect(() => { + if (validateForm()) { + setValidForm(true) + } else { + setValidForm(false) + } + }, [errors]) + + + const handleChange = (e) => { + if (e.target.id === 'business_name') { + if (e.target.value.length < 0) return + + setData((prev) => ({ ...prev, short_url: e.target.value.toLowerCase().replace(/\s+/g, '-') })) + } + + if (e.target.id === 'contact_Number') { + setErrors({ + ...errors, + phoneError: validPhoneRegex.test(e.target.value) ? '' : 'Number is not valid!', + }) + + + } + if (e.target.id === 'email') { + setErrors({ + ...errors, + emailError: validEmailRegex.test(e.target.value) ? '' : 'Email is not valid!', + }) + + + } + + if (e.target.id === 'image') { + if ( + e.target.files[0]?.type === 'image/jpeg' || + e.target.files[0]?.type === 'image/png' || + e.target.files[0]?.type === 'image/jpg' + ) { + setData((prev) => ({ + ...prev, + imageURL: URL.createObjectURL(e.target.files[0]), + image: e.target.files[0], + })) + return + } else { + swal({ + title: 'Warning', + text: 'Upload jpg, jpeg, png only.', + icon: 'error', + button: 'Close', + dangerMode: true, + }) + setData((prev) => ({ + ...prev, + imageURL: '', + image: '', + })) + e.target.value = null + return + } + } + setData((prev) => ({ ...prev, [e.target.id]: e.target.value })) + } + + + + return ( +
+
+
+
+
+ Contacts +
+
+

+
+ +
+ + + + +
+
+
+
+
+
+
+
+
+ + handleChange(e)} + /> + {data.business_name.length > 0 &&

Remaining characters : {50 - data.business_name.length}

} +
+ +
+ + handleChange(e)} + /> + {errors.emailError && ( +

{errors.emailError}

+ )} +
+
+ + handleChange(e)} + /> + {errors.phoneError && ( +

{errors.phoneError}

+ )} +
+
+ + handleChange(e)} + /> +
+
+ +
+ + {data.WebsiteURL} + + handleChange(e)} + /> +
+
+ + + + {/*
+ + handleChange(e)} + /> +

Upload jpg, jpeg and png only*

+
+
+ Uploaded Image will be shown here +
*/} + + + + + +
+
+
+ +
+
+ ) +} + +export default Contacts diff --git a/src/views/Business/multiform/selectLanguage.js b/src/views/Business/multiform/selectLanguage.js index 629c10d..769dab6 100644 --- a/src/views/Business/multiform/selectLanguage.js +++ b/src/views/Business/multiform/selectLanguage.js @@ -101,7 +101,7 @@ const selectLanguage = (props) => { marginRight: '5px', }} - onClick={() => props.handleView(2)} + onClick={() => props.handleView(3)} > Prev @@ -117,7 +117,7 @@ const selectLanguage = (props) => { textTransform: 'capitalize', // marginRight: '5px', }} - onClick={() => props.handleView(4)} + onClick={() => props.handleView(5)} // disabled={loading} // disabled={data.language.length < 0 && data.language.length > 3}