Skip to content

Commit 92c8418

Browse files
authored
Merge pull request #620 from tekdi/main-learner
Main learner qa
2 parents 5392e80 + 0e6fd0e commit 92c8418

File tree

27 files changed

+1664
-391
lines changed

27 files changed

+1664
-391
lines changed
539 KB
Loading
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
'use client';
2+
3+
import React, { useEffect, useRef, useState } from 'react';
4+
import { Box, IconButton, Typography } from '@mui/material';
5+
import Header from '@learner/components/Header/Header';
6+
import ResetPasswordForm from '@learner/components/ResetPasswordForm/ResetPasswordForm';
7+
import SimpleModal from '@learner/components/SimpleModal/SimpleModal';
8+
import { showToastMessage } from '@learner/components/ToastComponent/Toastify';
9+
import { sendOTP, verifyOTP } from '@learner/utils/API/OtPService';
10+
import OtpVerificationComponent from '@learner/components/OtpVerificationComponent/OtpVerificationComponent';
11+
import { maskMobileNumber } from '@learner/utils/helper';
12+
import { useRouter } from 'next/navigation';
13+
import PasswordResetSuccess from '@forget-password/Components/PasswordResetSuccess/PasswordResetSuccess';
14+
import { login, resetPassword } from '@learner/utils/API/LoginService';
15+
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
16+
import Layout from '../../components/Layout';
17+
18+
const ChangePassword = () => {
19+
const [otp, setOtp] = useState<string[]>(['', '', '', '']);
20+
const [otpmodal, setOtpModal] = useState(false);
21+
const [hash, setHash] = useState<string>('');
22+
23+
const [mobile] = useState(
24+
typeof window !== 'undefined'
25+
? localStorage.getItem('usermobile') || ''
26+
: ''
27+
);
28+
const [resetPasswordSuccessModal, setResetPasswordSuccessModal] =
29+
useState(false);
30+
const router = useRouter();
31+
32+
const handleResetPassword = async (
33+
oldPassword: string,
34+
newPassword: string,
35+
confirmPassword: string
36+
) => {
37+
try {
38+
let userIdName = localStorage.getItem('userIdName');
39+
if (userIdName) {
40+
try {
41+
const response = await login({
42+
username: userIdName,
43+
password: oldPassword,
44+
});
45+
try {
46+
if (response) {
47+
console.log('hii');
48+
const response = await resetPassword(newPassword);
49+
console.log('Password reset response:', response);
50+
setResetPasswordSuccessModal(true);
51+
} else {
52+
showToastMessage(
53+
'The old password you entered is incorrect',
54+
'error'
55+
);
56+
}
57+
} catch (error) {
58+
console.log('error');
59+
}
60+
} catch (error) {
61+
showToastMessage(
62+
'The old password you entered is incorrect',
63+
'error'
64+
);
65+
}
66+
}
67+
68+
// const response = await resetPassword(newPassword);
69+
// console.log('Password reset response:', response);
70+
} catch (error) {}
71+
// Add API call logic here
72+
};
73+
74+
const handleForgotPassword = async () => {
75+
try {
76+
let reason = 'forgot';
77+
const response = await sendOTP({ mobile: mobile, reason });
78+
console.log('sendOTP', response);
79+
setHash(response?.result?.data?.hash);
80+
setOtpModal(true);
81+
} catch (error) {}
82+
console.log('Forgot Password clicked');
83+
// Navigate or show forgot password modal
84+
};
85+
const onVerify = async () => {
86+
try {
87+
// let mobile = mobile.toString();
88+
let reason = 'forgot';
89+
// let username = enterdUserName;
90+
const response = await verifyOTP({
91+
mobile: localStorage.getItem('usermobile') || '',
92+
reason,
93+
otp: otp.join(''),
94+
hash,
95+
// username,
96+
});
97+
console.log('verifyOtp', response);
98+
let isValid = response.result.success;
99+
localStorage.setItem('tokenForResetPassword', response.result.token); // temporary assume true
100+
// let isValid = true;
101+
if (isValid) {
102+
// setVerificationSuccessModal(true);
103+
setOtpModal(false);
104+
localStorage.setItem('redirectionRoute', '/profile');
105+
router.push('/reset-Password');
106+
} else {
107+
showToastMessage('Please enter valid otp', 'error');
108+
}
109+
} catch (error) {
110+
showToastMessage('Please enter valid otp', 'error');
111+
} finally {
112+
setOtp(['', '', '', '']);
113+
}
114+
};
115+
const onResend = async () => {
116+
try {
117+
let reason = 'forgot';
118+
const response = await sendOTP({ mobile: mobile, reason });
119+
console.log('sendOTP', response);
120+
setHash(response?.result?.data?.hash);
121+
} catch (error) {}
122+
};
123+
const handleOTPModal = () => {
124+
setOtpModal(false);
125+
setOtp(['', '', '', '']);
126+
};
127+
const onCloseSuccessModal = () => {
128+
// const route = localStorage.getItem('redirectionRoute');
129+
// if (route)
130+
router.push('/profile');
131+
132+
setResetPasswordSuccessModal(false);
133+
};
134+
135+
return (
136+
<>
137+
<Layout>
138+
<Box
139+
sx={{ display: 'flex', alignItems: 'center', mb: 2, mt: 2 }}
140+
onClick={() => router.back()}
141+
>
142+
<IconButton>
143+
<ArrowBackIcon />
144+
</IconButton>
145+
</Box>
146+
<Box
147+
height="100vh"
148+
width="100vw"
149+
display="flex"
150+
flexDirection="column"
151+
overflow="auto"
152+
mt="70px"
153+
>
154+
<Typography
155+
variant="body1"
156+
mb="20px"
157+
sx={{
158+
fontWeight: 600,
159+
fontSize: '24px',
160+
lineHeight: '32px',
161+
letterSpacing: '0px',
162+
textAlign: 'center',
163+
}}
164+
>
165+
Change Password
166+
</Typography>
167+
<ResetPasswordForm
168+
onResetPassword={handleResetPassword}
169+
onForgotPassword={handleForgotPassword}
170+
/>
171+
</Box>
172+
<SimpleModal
173+
open={otpmodal}
174+
onClose={handleOTPModal}
175+
showFooter
176+
primaryText={'Verify OTP'}
177+
modalTitle={'Verify Your Phone Number'}
178+
primaryActionHandler={onVerify}
179+
>
180+
<OtpVerificationComponent
181+
onResend={onResend}
182+
otp={otp}
183+
setOtp={setOtp}
184+
maskedNumber={maskMobileNumber(mobile || '')}
185+
/>
186+
</SimpleModal>
187+
<SimpleModal
188+
open={resetPasswordSuccessModal}
189+
onClose={onCloseSuccessModal}
190+
showFooter
191+
primaryText={'Okay'}
192+
primaryActionHandler={onCloseSuccessModal}
193+
>
194+
<PasswordResetSuccess />
195+
</SimpleModal>
196+
</Layout>
197+
</>
198+
);
199+
};
200+
201+
export default ChangePassword;
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
'use client';
2+
3+
import React, { useEffect, useRef, useState } from 'react';
4+
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
5+
import { Box, Typography, Button, Paper } from '@mui/material';
6+
import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline';
7+
import { IconButton } from '@mui/material';
8+
import Header from '@learner/components/Header/Header';
9+
import { useRouter } from 'next/navigation';
10+
import Layout from '../../components/Layout';
11+
import UsernameSuggestion from '@learner/components/UsernameSuggestion/UsernameSuggestion';
12+
import { updateUser, userNameExist } from '@learner/utils/API/userService';
13+
import js from '@eslint/js';
14+
import SimpleModal from '@learner/components/SimpleModal/SimpleModal';
15+
const ChangeUserNamePage = () => {
16+
const router = useRouter();
17+
const [username, setUsername] = useState('');
18+
const [suggestions, setuggestions] = useState<any>([]);
19+
const [usernameChangedSuceesModal, setUsernameChangedSuceesModal] =
20+
useState(false);
21+
// const suggestions = ['anagadhinesh789', 'anagadhinesh267', 'anagadhinesh342'];
22+
23+
const handleContinue = async () => {
24+
console.log('Selected Username:', username);
25+
const userData = JSON.parse(localStorage.getItem('userResponse') || '{}');
26+
const data = {
27+
firstName: userData?.firstName,
28+
lastName: userData?.lastName,
29+
username: username,
30+
};
31+
await validateUsername(data);
32+
};
33+
const handleUsernameChange = (
34+
e: React.ChangeEvent<HTMLInputElement> | string
35+
) => {
36+
if (typeof e === 'string') {
37+
setUsername(e);
38+
} else {
39+
setUsername(e.target.value);
40+
}
41+
};
42+
const validateUsername = async (userData: {
43+
firstName: string;
44+
lastName: string;
45+
username: string;
46+
}) => {
47+
try {
48+
if (suggestions.length === 0) {
49+
const response = await userNameExist(userData);
50+
setuggestions([response?.suggestedUsername]);
51+
52+
console.log('response', response);
53+
}
54+
} catch (error: any) {
55+
if (error.response) {
56+
// Server responded with a status code outside the 2xx range
57+
console.log(
58+
'Server responded with error:',
59+
error.response.data.params.errmsg
60+
);
61+
try {
62+
if (error.response.data.params.errmsg === 'User does not exist') {
63+
let userId = localStorage.getItem('userId');
64+
let userData = {
65+
username: username,
66+
};
67+
const object = {
68+
userData: userData,
69+
};
70+
if (userId) {
71+
const updateUserResponse = await updateUser(userId, object);
72+
setUsernameChangedSuceesModal(true);
73+
}
74+
// console.error('Error validating username:', error);
75+
}
76+
} catch (error) {
77+
console.error('Error validating username:', error);
78+
}
79+
}
80+
}
81+
};
82+
const onCloseSuccessModal = () => {
83+
// const route = localStorage.getItem('redirectionRoute');
84+
// if (route) router.push(route);
85+
86+
setUsernameChangedSuceesModal(false);
87+
router.push('/profile');
88+
};
89+
return (
90+
<Layout>
91+
<Box
92+
height="100vh"
93+
width="100vw"
94+
display="flex"
95+
flexDirection="column"
96+
overflow="hidden"
97+
>
98+
<Box
99+
sx={{ display: 'flex', alignItems: 'center', mb: 2, mt: 2 }}
100+
onClick={() => router.back()}
101+
>
102+
<IconButton>
103+
<ArrowBackIcon />
104+
</IconButton>
105+
</Box>
106+
<UsernameSuggestion
107+
value={username}
108+
onChange={handleUsernameChange}
109+
suggestions={suggestions}
110+
onContinue={handleContinue}
111+
setSuggestions={setuggestions}
112+
/>
113+
</Box>
114+
<SimpleModal
115+
open={usernameChangedSuceesModal}
116+
onClose={onCloseSuccessModal}
117+
showFooter={true}
118+
primaryText={'Okay'}
119+
primaryActionHandler={onCloseSuccessModal}
120+
>
121+
<Box
122+
display="flex"
123+
justifyContent="center"
124+
alignItems="center"
125+
flexDirection={'column'}
126+
>
127+
<CheckCircleOutlineIcon
128+
sx={{ fontSize: 48, color: 'green', mb: 2 }}
129+
/>
130+
<Typography
131+
sx={{
132+
fontWeight: 400,
133+
fontSize: '22px',
134+
lineHeight: '28px',
135+
letterSpacing: '0px',
136+
textAlign: 'center',
137+
verticalAlign: 'middle',
138+
mb: 3,
139+
}}
140+
>
141+
Awesome!
142+
</Typography>
143+
<Typography
144+
sx={{
145+
fontWeight: 200,
146+
fontSize: '22px',
147+
lineHeight: '28px',
148+
letterSpacing: '0px',
149+
textAlign: 'center',
150+
verticalAlign: 'middle',
151+
mb: 3,
152+
}}
153+
>
154+
Your username has been successfully changed{' '}
155+
</Typography>
156+
</Box>
157+
</SimpleModal>
158+
</Layout>
159+
);
160+
};
161+
162+
export default ChangeUserNamePage;

apps/learner-web-app/src/app/content-details/[identifier]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const App = () => {
2424
isShowLayout={false}
2525
_config={{
2626
default_img: '/images/image_ver.png',
27-
_infoCard: { _cardMedia: { maxHeight: '280px' } },
27+
_infoCard: { _cardMedia: { maxHeight: '244px' } },
2828
}}
2929
/>
3030
</Box>

apps/learner-web-app/src/app/content/[courseId]/[unitId]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const App = () => {
2323
_config={{
2424
default_img: '/images/image_ver.png',
2525
_card: { isHideProgress: true },
26-
_infoCard: { _cardMedia: { maxHeight: '280px' } },
26+
_infoCard: { _cardMedia: { maxHeight: '244px' } },
2727
}}
2828
/>
2929
</Box>

apps/learner-web-app/src/app/content/[courseId]/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ const App = () => {
2121
<CourseUnitDetails
2222
isShowLayout={false}
2323
_config={{
24-
default_img: '/images/image_ver.png',
24+
default_img: '/images/unit.png',
2525
_card: { isHideProgress: true },
26-
_infoCard: { _cardMedia: { maxHeight: '280px' } },
26+
_infoCard: { _cardMedia: { maxHeight: '244px' } },
27+
_grid: { xs: 6, sm: 4, md: 3, lg: 2.5 },
2728
}}
2829
/>
2930
</Box>

0 commit comments

Comments
 (0)