Skip to content

Commit 7e8c8d1

Browse files
fix profile settings
1 parent f64c3ae commit 7e8c8d1

File tree

7 files changed

+48
-20
lines changed

7 files changed

+48
-20
lines changed

src/assets/styles/UserProfile.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@
230230

231231
.error {
232232
color: red !important;
233-
padding: 0 !important;
233+
padding-left: 2rem !important;
234+
margin-left: -2rem;
234235
background: none;
235236
font-size: 2rem;
236237
}

src/components/product/SellerProduct.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { PuffLoader } from 'react-spinners';
1212
import { Meta } from '../Meta';
1313
import { toast } from 'react-toastify';
1414
import { getErrorMessage } from '../../utils/axios/axiosInstance';
15-
import { deleteItem } from '../../store/features/product/sellerCollectionProductsSlice';
15+
// import { deleteItem } from '../../store/features/product/sellerCollectionProductsSlice';
1616
import ConfirmModal from './ConfirmModal';
1717

1818
const initialProductState: ISingleProduct = {
@@ -126,7 +126,7 @@ const SellerProduct = ({ productId }: { productId: string }) => {
126126

127127
const handleDelete = async () => {
128128
if (updatedProduct) {
129-
await dispatch(deleteItem(itemToDelete));
129+
// await dispatch(deleteItem(itemToDelete));
130130
setShowConfirm(false);
131131
navigate('/seller/products');
132132
}

src/components/user/PasswordUpdate.tsx

+18-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
88
import { faEye, faEyeSlash } from '@fortawesome/free-solid-svg-icons';
99
import { toast } from "react-toastify";
1010
import { TailSpin } from 'react-loader-spinner';
11+
import { logout } from '../../store/features/auth/authSlice';
12+
import { disconnect } from '../../utils/socket/socket';
13+
import { useNavigate } from 'react-router-dom';
1114

1215
const passwordSchema = Yup.object({
1316
oldPassword: Yup.string().required('Old password is required'),
@@ -25,6 +28,7 @@ const PasswordUpdate = ({ message, isError, isSuccess }) => {
2528
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
2629
const [showConfirmNewPassword, setShowConfirmNewPassword] = useState(false)
2730
const [loading, setLoading] = useState(false);
31+
const navigate = useNavigate()
2832

2933
const newPasswordVisibility = () => {
3034
setShowPassword(!showPassword);
@@ -45,13 +49,23 @@ const PasswordUpdate = ({ message, isError, isSuccess }) => {
4549
},
4650
validationSchema: passwordSchema,
4751
onSubmit: async (values) => {
48-
setLoading(true);
4952
try{
53+
setTimeout(()=>{
54+
setLoading(true)
55+
},200)
5056
dispatch(updatePassword(values));
5157
}catch(err){
5258
console.log(err)
5359
}finally{
5460
setLoading(false)
61+
toast.success("Password updated Successfully you will be logged out in few second ")
62+
setTimeout(()=>{
63+
dispatch(logout())
64+
disconnect()
65+
},4000)
66+
setTimeout(()=>{
67+
navigate("/login")
68+
}, 5500)
5569
}
5670

5771
},
@@ -74,7 +88,7 @@ const PasswordUpdate = ({ message, isError, isSuccess }) => {
7488
<div className="password">
7589
<div className='password-layout'>
7690
<div className="password-inp">
77-
<label htmlFor="oldPassword">old password</label>
91+
<label htmlFor="oldPassword">Old Password</label>
7892
<div className="input-n">
7993
<input
8094
type={showPassword ? 'text' : 'password'}
@@ -102,7 +116,7 @@ const PasswordUpdate = ({ message, isError, isSuccess }) => {
102116
<div >
103117
<div className='conf-pwd'>
104118
<div className="password-inp">
105-
<label htmlFor="newPassword">new Password</label>
119+
<label htmlFor="newPassword">New Password</label>
106120
<div className="input-n">
107121
<input
108122
type={showConfirmPassword ? 'text' : 'password'}
@@ -126,7 +140,7 @@ const PasswordUpdate = ({ message, isError, isSuccess }) => {
126140
{formik.errors.newPassword && <div className='error'>{formik.errors.newPassword}</div>}
127141
</div>
128142
<div className="password-inp">
129-
<label htmlFor="confirmNewPassword">confirm New Password</label>
143+
<label htmlFor="confirmNewPassword">Confirm New Password</label>
130144
<div className="input-n">
131145
<input
132146
type={showConfirmNewPassword ? 'text' : 'password'}

src/components/user/ProfileDetails.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ const updateProfileSchema = Yup.object().shape({
2222
currency: Yup.string().required('Required'),
2323
});
2424

25-
const ProfileDetails = ({ user, isLoading, isSuccess, isError, message }) => {
25+
const ProfileDetails = ({ user, isSuccess, isError, message }) => {
2626
const dispatch = useAppDispatch();
2727
const inputRef = useRef(null);
2828
const [profileImage, setProfileImage] = useState<any>(null);
29+
const [loading, setLoading] = useState(false)
2930

3031
useEffect(() => {
3132
dispatch(fetchUserProfile());
@@ -74,8 +75,14 @@ const ProfileDetails = ({ user, isLoading, isSuccess, isError, message }) => {
7475
formData.append("language", values.language);
7576
formData.append("birthDate", values.birthDate);
7677

77-
const response: any = await dispatch(updateUserProfile(formData));
78-
// if(response && response.payload && response.payload.status && response.paylad.message) toast.success(response.payload.message);
78+
setTimeout(()=>{
79+
setLoading(true)
80+
},2000)
81+
await dispatch(updateUserProfile(formData))
82+
.finally(()=>{
83+
setLoading(false)
84+
});
85+
7986
}
8087
});
8188

@@ -113,7 +120,7 @@ const ProfileDetails = ({ user, isLoading, isSuccess, isError, message }) => {
113120
<div className='title'>
114121
<h1>MY PROFILE DETAILS</h1>
115122
<button type='submit'>
116-
{isLoading ? (
123+
{loading ? (
117124
<div className="spinner-container">
118125
<TailSpin color="#ff6d18" width={20} />
119126
</div>

src/components/user/ShippingAddress.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ interface RwandaLocationSelectorProps {
1313
user: IProfile,
1414
isSuccess: boolean,
1515
isError: string,
16-
isLoading: boolean,
1716
message: string
1817
}
1918

@@ -35,14 +34,15 @@ interface RwandaLocationSelectorProps {
3534

3635
const rwandaData: RwandaData = data;
3736

38-
const ShippingAddress:React.FC<RwandaLocationSelectorProps> = ({ user,isSuccess, isError, isLoading,message,setLocation }) => {
37+
const ShippingAddress:React.FC<RwandaLocationSelectorProps> = ({ user,isSuccess, isError,message,setLocation }) => {
3938

4039
const dispatch = useAppDispatch();
4140
const [country, setCountry] = useState('Rwanda');
4241
const [province, setProvince] = useState('');
4342
const [district, setDistrict] = useState('');
4443
const [sector, setSector] = useState('');
4544
const [street, setStreet] = useState("")
45+
const [loading, setLoading] = useState(false)
4646

4747
const handleProvinceChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
4848
setProvince(e.target.value);
@@ -70,7 +70,13 @@ const ShippingAddress:React.FC<RwandaLocationSelectorProps> = ({ user,isSuccess,
7070
return;
7171
}
7272
try {
73-
dispatch(addUserAddress({ id: user.id, data: {province, district, sector, street}}));
73+
setTimeout(()=>{
74+
setLoading(true)
75+
},200)
76+
dispatch(addUserAddress({ id: user.id, data: {province, district, sector, street}}))
77+
.finally(()=>{
78+
setLoading(false)
79+
});
7480
} catch (error) {
7581
toast.error(isError);
7682
}
@@ -93,7 +99,7 @@ const ShippingAddress:React.FC<RwandaLocationSelectorProps> = ({ user,isSuccess,
9399
<div className='title'>
94100
<h1>MY SHIPPING ADDRESS</h1>
95101
<button type='submit'>
96-
{isLoading ? (
102+
{loading ? (
97103
<div className="spinner-container">
98104
<TailSpin color="#ff6d18" width={20} />
99105
</div>

src/pages/UserEditProfile.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ const UserProfile = () => {
3636
return (
3737
<>
3838
<section className='profile-container'>
39-
<ProfileDetails user={user} isSuccess={isSuccess} isLoading={isLoading} isError={isError} message={message} />
39+
<ProfileDetails user={user} isSuccess={isSuccess} isError={isError} message={message} />
4040
<PasswordUpdate message={message} isSuccess={isSuccess} isError={isError}/>
41-
<ShippingAddress user={user} isLoading={isLoading} isSuccess={isSuccess} isError={isError} message={message} setLocation={setLocation} />
41+
<ShippingAddress user={user} isSuccess={isSuccess} isError={isError} message={message} setLocation={setLocation} />
4242
<div className="seller__request">
4343
<SubmitSellerRequest
4444
user={requestData}

src/pages/seller/SellerCollection.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import React, { useEffect, useState } from 'react'
33
import Table from '../../components/table/Table';
44
import { useAppDispatch, useAppSelector } from '../../store/store';
5-
import { fetchSellerCollectionProduct, deleteItem, removeItem } from '../../store/features/product/sellerCollectionProductsSlice';
5+
import { fetchSellerCollectionProduct} from '../../store/features/product/sellerCollectionProductsSlice';
66
import Zoom from '@mui/material/Zoom';
77
import Tooltip from '@mui/material/Tooltip';
88
import DeleteIcon from '@mui/icons-material/Delete';
@@ -47,8 +47,8 @@ export default function SellerCollection() {
4747
const handleDelete = async () => {
4848
try {
4949
setShowConfirm(false)
50-
dispatch(removeItem(itemToDelete.id))
51-
await dispatch(deleteItem(itemToDelete.id)).unwrap();
50+
// dispatch(removeItem(itemToDelete.id))
51+
// await dispatch(deleteItem(itemToDelete.id)).unwrap();
5252
dispatch(fetchSellerCollectionProduct());
5353
setItemToDelete(null)
5454
} catch (error) {

0 commit comments

Comments
 (0)