This commit is contained in:
pawan-dot 2022-10-18 12:36:20 +05:30
parent d21eb2dc5b
commit e89beffbce
23 changed files with 241 additions and 85 deletions

View File

@ -6,7 +6,7 @@ const AppFooter = () => {
<CFooter>
<div>
<span className="ms-1">{new Date().getFullYear()} &copy; Sales Champions.</span>
<span className="ms-1">{new Date().getFullYear()} &copy;CMP.</span>
</div>
</CFooter>

View File

@ -32,7 +32,7 @@ const AppHeader = () => {
<CIcon icon={cilMenu} size="lg" />
</CHeaderToggler>
<CHeaderBrand className="mx-auto d-md-none" to="/">
<h2>Sales Champions</h2>
<h1>CMP</h1>
</CHeaderBrand>
<CHeaderNav className="d-none d-md-flex me-auto">
<CNavItem>

View File

@ -31,7 +31,7 @@ const AppSidebar = () => {
>
<CSidebarBrand className="d-none bg-info d-md-flex" to="/">
{/* <CIcon className="sidebar-brand-full" icon={logoNegative} height={35} /> */}
<h3>Sales Champions</h3>
<h1>CMP</h1>
{/* <CIcon className="sidebar-brand-narrow" height={35} /> */}
<CIcon className="sidebar-brand-narrow" icon={sygnet} height={35} />
</CSidebarBrand>

View File

@ -11,8 +11,8 @@ import store from './store'
import axios from 'axios'
const setupAxios = () => {
axios.defaults.baseURL = 'https://cms-api-dashboard.herokuapp.com/';
//axios.defaults.baseURL = 'http://localhost:5000'
// axios.defaults.baseURL = 'https://cms-api-dashboard.herokuapp.com/';
axios.defaults.baseURL = 'http://localhost:5000'
axios.defaults.headers = {
'Cache-Control': 'no-cache,no-store',
'Pragma': 'no-cache',

View File

@ -43,8 +43,8 @@ const AddBanner = () => {
const handleSubmit = async () => {
if (!(title && subTitle && image && section && subSection && startDate && endDate)) {
alert("Please fill All required field ");
return;
return swal('Error!', 'All fields are required', 'error')
}
const myForm = new FormData();
@ -75,7 +75,7 @@ const AddBanner = () => {
}
} catch (error) {
alert(error)
swal('Error!', error, 'error')
setLoading(false);
}

View File

@ -59,8 +59,8 @@ const EditBanner = () => {
const handleSubmit = async () => {
if (!(title && subTitle && image && section && subSection && startDate && endDate)) {
alert("Please fill All required field ");
return;
return swal('Error!', 'All fields are required', 'error')
}
const myForm = new FormData();
@ -89,7 +89,7 @@ const EditBanner = () => {
history.goBack();
}
} catch (error) {
alert(error)
swal('Error!', error, 'error')
setLoading(false);
}
// console.log(image)

View File

@ -69,7 +69,8 @@ const EditCms = () => {
history.goBack()
}
} catch (error) {
alert(error)
swal('Error!', error, 'error')
changeState({ loading: false });
}

View File

@ -32,8 +32,8 @@ const AddProduct = () => {
const handleSubmit = async () => {
if (!(name && image)) {
alert("Please fill All required field ");
return;
return swal('Error!', 'All fields are required', 'error')
}
const myForm = new FormData();
@ -60,7 +60,8 @@ const AddProduct = () => {
history.goBack();
}
} catch (error) {
alert("something went wrong")
swal('Error!', "something went wrong", 'error')
setLoading(false);
}

View File

@ -44,8 +44,8 @@ const AddProduct = () => {
const handleSubmit = async () => {
if (!(name && image)) {
alert("Please fill All required field ");
return;
return swal('Error!', 'All fields are required', 'error')
}
const myForm = new FormData();
@ -72,7 +72,8 @@ const AddProduct = () => {
history.goBack();
}
} catch (error) {
alert("something went wrong")
swal('Error!', "something went wrong", 'error')
setLoading(false);
}
}

View File

@ -75,8 +75,8 @@ const Add_Business = () => {
const handleSubmit = async () => {
if (!(state.name && state.phone && state.email && state.Bname && state.Sname && state.country && state.city && state.description
&& state.category && state.status && image)) {
alert("Please fill All required field ");
return;
return swal('Error!', 'All fields are required', 'error')
}
const myForm = new FormData();
@ -122,7 +122,8 @@ const Add_Business = () => {
history.goBack()
}
} catch (error) {
alert(error)
swal('Error!', error, 'error')
changeState({ loading: false });
}

View File

@ -96,8 +96,8 @@ const EditBisuness = () => {
const handleSubmit = async () => {
if (!(state.name && state.phone && state.email && state.Building_Name && state.Street_Name && state.country && state.city && state.description
&& state.category && state.status && image)) {
alert("Please fill All required field ");
return;
return swal('Error!', 'All fields are required', 'error')
}
const myForm = new FormData();
myForm.set('name', state.name)
@ -138,7 +138,8 @@ const EditBisuness = () => {
history.goBack()
}
} catch (error) {
alert(error)
swal('Error!', error, 'error')
changeState({ loading: false });
}

View File

@ -34,8 +34,8 @@ const AddEvent = () => {
const [loading, setLoading] = useState(false);
const handleSubmit = async () => {
if (!(title && description && image && location && time && date)) {
alert("Please fill All required field ");
return;
return swal('Error!', 'All fields are required', 'error')
}
const myForm = new FormData();
@ -64,7 +64,8 @@ const AddEvent = () => {
history.goBack();
}
} catch (error) {
alert("Something went Wrong")
swal('Error!', 'Something went Wrong', 'error')
setLoading(false);
}

View File

@ -53,8 +53,8 @@ const EditEvent = () => {
const handleSubmit = async () => {
if (!(title && description && image && location && time && date)) {
alert("Please fill All required field ");
return;
return swal('Error!', 'All fields are required', 'error')
}
const myForm = new FormData();
@ -84,7 +84,8 @@ const EditEvent = () => {
}
} catch (error) {
alert("Something went Wrong")
swal('Error!', 'Something went Wrong', 'error')
setLoading(false);
}

View File

@ -31,8 +31,8 @@ const AddFaqs = () => {
const handleSubmit = async () => {
if (!(topic && description)) {
alert("Please fill All required field ");
return;
return swal('Error!', 'All fields are required', 'error')
}
const myForm = new FormData();
@ -58,7 +58,8 @@ const AddFaqs = () => {
history.goBack();
}
} catch (error) {
alert(error)
swal('Error!', error, 'error')
setLoading(false);
}

View File

@ -42,8 +42,8 @@ const EditFaqs = () => {
}, [id]);
const handleSubmit = async () => {
if (!(topic && description)) {
alert("Please fill All required field ");
return;
return swal('Error!', 'All fields are required', 'error')
}
const myForm = new FormData();
@ -69,7 +69,8 @@ const EditFaqs = () => {
history.goBack();
}
} catch (error) {
alert(error)
swal('Error!', error, 'error')
setLoading(false);
}

View File

@ -31,8 +31,8 @@ const AddNews = () => {
const handleSubmit = async () => {
if (!(title && description && image)) {
alert("Please fill All required field ");
return;
return swal('Error!', 'All fields are required', 'error')
}
const myForm = new FormData();
@ -58,7 +58,8 @@ const AddNews = () => {
history.goBack();
}
} catch (error) {
alert(error)
swal('Error!', error, 'error')
setLoading(false);
}

View File

@ -46,8 +46,8 @@ const EditNews = () => {
const handleSubmit = async () => {
if (!(title && description && image)) {
alert("Please fill All required field ");
return;
return swal('Error!', 'All fields are required', 'error')
}
const myForm = new FormData();
@ -73,7 +73,8 @@ const EditNews = () => {
history.goBack();
}
} catch (error) {
alert(error)
swal('Error!', error, 'error')
setLoading(false);
}

View File

@ -63,8 +63,8 @@ const AddOffer = () => {
const handleSubmit = async () => {
if (!(title && description && image && location && sendBisunessName)) {
alert("Please fill All required field ");
return;
return swal('Error!', 'All fields are required', 'error')
}
const myForm = new FormData();
@ -93,7 +93,8 @@ const AddOffer = () => {
}
} catch (error) {
alert("something Went Wrong")
swal('Error!', 'something Went Wrong', 'error')
setLoading(false);
}

View File

@ -72,8 +72,8 @@ const EditOffer = () => {
const handleSubmit = async () => {
if (!(title && description && image && location && sendBisunessName)) {
alert("Please fill All required field ");
return;
return swal('Error!', 'All fields are required', 'error')
}
const myForm = new FormData();
@ -101,7 +101,8 @@ const EditOffer = () => {
history.goBack();
}
} catch (error) {
alert("something Went Wrong")
swal('Error!', 'something Went Wrong', 'error')
setLoading(false);
}

View File

@ -67,8 +67,8 @@ const AddRequirement = () => {
});
if (!(title && description && areaOfInterest && allimage[0])) {
alert("please fill all fields")
return
return swal('Error!', 'All fields are required', 'error')
}
setLoading(true);
try {
@ -89,7 +89,8 @@ const AddRequirement = () => {
} catch (error) {
setLoading(false);
alert(error)
swal('Error!', error, 'error')
}

View File

@ -82,8 +82,8 @@ const EditRequirement = () => {
});
if (!(title && description && areaOfInterest && allimage[0])) {
alert("please fill all fields")
return
return swal('Error!', 'All fields are required', 'error')
}
setLoading(true);
try {
@ -104,7 +104,8 @@ const EditRequirement = () => {
} catch (error) {
setLoading(false);
alert(error)
swal('Error!', error, 'error')
}

View File

@ -1,4 +1,4 @@
import React from 'react'
import React, { useEffect } from 'react'
import { Link } from 'react-router-dom'
import {
CButton,
@ -22,20 +22,80 @@ import { useHistory } from 'react-router-dom'
const Login = () => {
const [loading, setLoading] = useState(false);
const [validForm, setValidForm] = useState(false)
const [auth, setAuth] = useState({
email: "",
password: ""
});
const history = useHistory();
const [errors, setErrors] = useState({
emailError: '',
passwordError: '',
const handleChange = (e) => (event) => {
setAuth({ ...auth, [e]: event.target.value });
};
})
const validEmailRegex = RegExp(
/^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i,
)
const validPasswordRegex = RegExp(/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[^\w\s]).{7,}$/)
const history = useHistory();
// const handleChange = (e) => (event) => {
// setAuth({ ...auth, [e]: event.target.value });
// };
const validateForm = () => {
let valid = true
Object.values(errors).forEach((val) => {
if (val.length > 0) {
valid = false
return false
}
})
Object.values(auth).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) => {
const { name, value } = e.target
switch (name) {
case 'email':
setErrors({
...errors,
emailError: validEmailRegex.test(value) ? '' : 'Email is not valid!',
})
break
case 'password':
setErrors((errors) => ({
...errors,
passwordError: validPasswordRegex.test(value)
? ''
: 'Password Shoud Be 8 Characters Long, Atleast One Uppercase, Atleast One Lowercase,Atleast One Digit, Atleast One Special Character',
}))
break
default:
break
}
setAuth({ ...auth, [name]: value })
}
const Login = async () => {
if (!(auth.email && auth.password)) {
alert("please filled both fields")
return
return swal('Error!', 'All fields are required', 'error')
}
setLoading({ loading: true })
try {
@ -55,7 +115,7 @@ const Login = () => {
window.location.reload()
}
else {
alert("please try with admin credential!!")
swal('Error!', 'please try with admin credential!!', 'error')
setLoading(false);
}
@ -64,12 +124,14 @@ const Login = () => {
}
else {
setLoading(false);
alert("Invalid Credential");
swal('Error!', 'Invalid Credentials', 'error')
}
} catch (error) {
setLoading(false);
alert("Invalid Credentials");
swal('Error!', 'Invalid Credentials', 'error')
}
}
@ -84,27 +146,34 @@ const Login = () => {
<CCardBody>
<CForm>
<h1>Login</h1>
<p className="text-medium-emphasis">Sign In to Your Sales Champions Dashboard Account.</p>
<p className="text-medium-emphasis">Sign In to Your CMP Dashboard Account.</p>
<CInputGroup className="mb-3">
<CInputGroupText>
<CIcon icon={cilUser} />
</CInputGroupText>
<CFormInput placeholder="Email" onChange={handleChange("email")} autoComplete="email" />
<CFormInput type="email" placeholder="Email" onChange={handleChange} value={auth.email} name="email" autoComplete="email" />
</CInputGroup>
{errors.emailError && (
<p className="text-center py-2 text-danger">{errors.emailError}</p>
)}
<CInputGroup className="mb-4">
<CInputGroupText>
<CIcon icon={cilLockLocked} />
</CInputGroupText>
<CFormInput
type="password"
onChange={handleChange("password")}
name="password"
value={auth.password}
onChange={handleChange}
placeholder="Password"
autoComplete="current-password"
/>
</CInputGroup>
<CButton color="primary" className="px-4" onClick={Login}>
{errors.passwordError && (
<p className="text-center py-2 text-danger">{errors.passwordError}</p>
)}
<CButton color="primary" className="px-4" disabled={!validForm} onClick={Login}>
<ClipLoader loading={loading} size={18} />
{!loading && "Login"}

View File

@ -20,27 +20,77 @@ import Swal from 'sweetalert2'
import { useHistory } from 'react-router-dom'
const Register = () => {
const [oldPassword, setOldPassword] = useState();
const [newPassword, setNewPassword] = useState();
const [confirmPassword, setConfirmPassword] = useState();
const [loading, setLoading] = useState(false);
const history = useHistory();
const [user, setUser] = useState({
oldPassword: '',
newPassword: '',
confirmPassword: '',
})
const [errors, setErrors] = useState({
confirmPasswordError: '',
newPasswordError: '',
oldPasswordError: '',
})
const validEmailRegex = RegExp(
/^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i,
)
const validPasswordRegex = RegExp(/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[^\w\s]).{7,}$/)
const handleChange = (e) => {
const { name, value } = e.target
switch (name) {
case 'oldPassword':
setErrors({
...errors,
oldPasswordError: validPasswordRegex.test(value)
? ''
: 'Password Shoud Be 8 Characters Long, Atleast One Uppercase, Atleast One Lowercase,Atleast One Digit, Atleast One Special Character',
})
break
case 'newPassword':
setErrors({
...errors,
newPasswordError: validPasswordRegex.test(value)
? ''
: 'Password Shoud Be 8 Characters Long, Atleast One Uppercase, Atleast One Lowercase,Atleast One Digit, Atleast One Special Character',
})
break
case 'confirmPassword':
setErrors((errors) => ({
...errors,
confirmPasswordError: validPasswordRegex.test(value)
? ''
: 'Password Shoud Be 8 Characters Long, Atleast One Uppercase, Atleast One Lowercase,Atleast One Digit, Atleast One Special Character',
}))
break
default:
break
}
setUser({ ...user, [name]: value })
}
const handleSubmit = async () => {
if (!(oldPassword && newPassword && confirmPassword)) {
alert("Please fill All required field ");
return;
if (!(user.oldPassword && user.newPassword && user.confirmPassword)) {
return swal('Error!', 'All fields are required', 'error')
}
if (!(user.newPassword.length >= 8)) {
return swal('Error!', 'All fields are required', 'error');
}
const token = localStorage.getItem("authToken")
setLoading({ loading: true })
if (newPassword == confirmPassword) {
if (user.newPassword == user.confirmPassword) {
let res = await axios.put('/api/v1/user/password/update',
{
oldPassword
, newPassword,
confirmPassword
...user
}, {
headers: {
Authorization: `Bearer ${token}`,
@ -63,7 +113,7 @@ const Register = () => {
}
setLoading(false);
} else {
alert('new password and confirm password are not matched')
swal('Error!', 'New Password And Confirm Password is Not Match !', 'error')
setLoading(false);
}
@ -83,29 +133,51 @@ const Register = () => {
<CInputGroupText>
<CIcon icon={cilLockLocked} />
</CInputGroupText>
<CFormInput placeholder="Old Password" type="password" onChange={(e) => setOldPassword(e.target.value)} />
<CFormInput placeholder="Old Password" type="password" value={user.oldPassword}
onChange={handleChange}
autoComplete="current-password"
name="oldPassword" />
</CInputGroup>
{errors.oldPasswordError && (
<p className="text-center py-2 text-danger">{errors.oldPasswordError}</p>
)}
<CInputGroup className="mb-3">
<CInputGroupText>
<CIcon icon={cilLockLocked} />
</CInputGroupText>
<CFormInput
type="password"
placeholder="Password"
placeholder=" New Password"
value={user.newPassword}
onChange={handleChange}
name="newPassword"
onChange={(e) => setNewPassword(e.target.value)}
/>
</CInputGroup>
{errors.newPasswordError && (
<p className="text-center py-2 text-danger">{errors.newPasswordError}</p>
)}
<CInputGroup className="mb-4">
<CInputGroupText>
<CIcon icon={cilLockLocked} />
</CInputGroupText>
{errors.passwordError && (
<p className="text-center py-2 text-danger">{errors.passwordError}</p>
)}
<CFormInput
type="password"
placeholder="Confirm password"
onChange={(e) => setConfirmPassword(e.target.value)}
placeholder="Confirm password "
value={user.confirmPassword}
onChange={handleChange}
name="confirmPassword"
/>
</CInputGroup>
{errors.confirmPasswordError && (
<p className="text-center py-2 text-danger">{errors.confirmPasswordError}</p>
)}
<div className="d-grid">
<CButton color="success" onClick={handleSubmit}>
<ClipLoader loading={loading} size={18} />