Skip to content

Commit 62cef15

Browse files
authored
Merge pull request #650 from tekdi/main-learner
Main learner qa
2 parents 98951f6 + 2f572ef commit 62cef15

File tree

10 files changed

+79
-12
lines changed

10 files changed

+79
-12
lines changed

apps/learner-web-app/src/app/change-password/page.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import PasswordResetSuccess from '@forget-password/Components/PasswordResetSucce
1414
import { login, resetPassword } from '@learner/utils/API/LoginService';
1515
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
1616
import Layout from '../../components/Layout';
17-
17+
import { checkAuth } from '@shared-lib-v2/utils/AuthService';
1818
const ChangePassword = () => {
1919
const [otp, setOtp] = useState<string[]>(['', '', '', '']);
2020
const [otpmodal, setOtpModal] = useState(false);
@@ -131,6 +131,12 @@ const ChangePassword = () => {
131131

132132
setResetPasswordSuccessModal(false);
133133
};
134+
useEffect(() => {
135+
// const token = localStorage.getItem('token');
136+
if (!checkAuth()) {
137+
router.push('/login');
138+
}
139+
}, []);
134140

135141
return (
136142
<>

apps/learner-web-app/src/app/change-username/page.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import UsernameSuggestion from '@learner/components/UsernameSuggestion/UsernameS
1212
import { updateUser, userNameExist } from '@learner/utils/API/userService';
1313
import js from '@eslint/js';
1414
import SimpleModal from '@learner/components/SimpleModal/SimpleModal';
15+
import { checkAuth } from '@shared-lib-v2/utils/AuthService';
16+
1517
const ChangeUserNamePage = () => {
1618
const router = useRouter();
1719
const [username, setUsername] = useState('');
@@ -86,6 +88,11 @@ const ChangeUserNamePage = () => {
8688
setUsernameChangedSuceesModal(false);
8789
router.push('/profile');
8890
};
91+
useEffect(() => {
92+
if (!checkAuth()) {
93+
router.push('/login');
94+
}
95+
}, []);
8996
return (
9097
<Layout>
9198
<Box

apps/learner-web-app/src/app/login/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useRouter } from 'next/navigation';
1111
import { useMediaQuery, useTheme } from '@mui/material';
1212
import FingerprintJS from '@fingerprintjs/fingerprintjs';
1313
import { Loader, useTranslation } from '@shared-lib';
14+
import { preserveLocalStorage } from '@learner/utils/helper';
1415

1516
const Login = dynamic(
1617
() => import('@login/Components/LoginComponent/LoginComponent'),
@@ -31,6 +32,9 @@ const LoginPage = () => {
3132
useEffect(() => {
3233
const init = async () => {
3334
try {
35+
// localStorage.clear();()
36+
preserveLocalStorage();
37+
3438
const access_token = localStorage.getItem('token');
3539
const refresh_token = localStorage.getItem('refreshToken');
3640
if (access_token) {
@@ -91,6 +95,7 @@ const LoginPage = () => {
9195
display="flex"
9296
flexDirection="column"
9397
overflow="hidden"
98+
sx={{ overflowWrap: 'break-word', wordBreak: 'break-word' }}
9499
>
95100
{/* Fixed Header */}
96101
<Header />

apps/learner-web-app/src/app/profile-complition/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { useSearchParams } from 'next/navigation';
77
const ProfileComplitionInner = () => {
88
const searchParams = useSearchParams();
99
const isComplition = searchParams.get('isComplition');
10-
1110
return <EditProfile completeProfile={isComplition ? true : false} />;
1211
};
1312

apps/learner-web-app/src/app/profile/page.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import UserProfileCard from '@learner/components/UserProfileCard/UserProfileCard
77
import CourseCertificateCard from '@learner/components/CourseCertificateCard/CourseCertificateCard';
88
import { courseWiseLernerList } from '@shared-lib-v2/utils/CertificateService/coursesCertificates';
99
import { CertificateModal, get } from '@shared-lib';
10+
import { useRouter } from 'next/navigation';
11+
import { checkAuth } from '@shared-lib-v2/utils/AuthService';
1012

1113
import { baseurl } from '@learner/utils/API/EndUrls';
1214
type FilterDetails = {
@@ -15,6 +17,8 @@ type FilterDetails = {
1517
userId?: string;
1618
};
1719
const ProfilePage = () => {
20+
const router = useRouter();
21+
1822
const [filters] = useState<FilterDetails>({
1923
status: ['completed', 'viewCertificate'],
2024
tenantId:
@@ -81,7 +85,12 @@ const ProfilePage = () => {
8185
};
8286
prepareCertificateData();
8387
}, []);
84-
88+
useEffect(() => {
89+
// const token = localStorage.getItem('token');
90+
if (!checkAuth()) {
91+
router.push('/login');
92+
}
93+
}, []);
8594
return (
8695
<Layout>
8796
<Box display="flex" flexDirection={{ xs: 'column', md: 'row' }} gap={2}>

apps/learner-web-app/src/app/registration/RegisterUser.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ const RegisterUser = () => {
6868
const [username, setUsername] = useState('');
6969
const [password, setPassword] = useState('');
7070
const [mobile, setMobile] = useState('');
71+
const [tenantName, setTenantName] = useState('');
72+
7173
const router = useRouter();
7274

7375
const [confirmPassword, setConfirmPassword] = useState('');
@@ -77,6 +79,10 @@ const RegisterUser = () => {
7779
// const [schema, setSchema] = useState(facilitatorSearchSchema);
7880
// const [uiSchema, setUiSchema] = useState(facilitatorSearchUISchema);
7981
function checkTenantId(tenantIdToCheck: any, tenantData: any) {
82+
const name = tenantData?.find(
83+
(item: any) => item.tenantId === tenantIdToCheck
84+
).name;
85+
setTenantName(name);
8086
return tenantData?.some((item: any) => item.tenantId === tenantIdToCheck);
8187
}
8288
useEffect(() => {
@@ -480,7 +486,7 @@ const RegisterUser = () => {
480486
}}
481487
>
482488
<Typography variant="h2" fontWeight="bold" gutterBottom>
483-
Sign Up for YouthNet
489+
Sign Up for {tenantName}
484490
</Typography>
485491

486492
<Typography variant="body1" color="text.secondary" mb={2}>

apps/learner-web-app/src/components/EditProfile/EditProfile.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import ArrowBackIcon from '@mui/icons-material/ArrowBack';
2727
//build issue fix for ⨯ useSearchParams() should be wrapped in a suspense boundary at page
2828
import { useSearchParams } from 'next/navigation';
2929
import { getTenantInfo } from '@learner/utils/API/ProgramService';
30+
import { checkAuth } from '@shared-lib-v2/utils/AuthService';
31+
3032
import Image from 'next/image';
3133
import { set } from 'lodash';
3234
import {
@@ -65,7 +67,12 @@ const EditProfile = ({ completeProfile }: EditProfileProps) => {
6567

6668
// const [schema, setSchema] = useState(facilitatorSearchSchema);
6769
// const [uiSchema, setUiSchema] = useState(facilitatorSearchUISchema);
68-
70+
useEffect(() => {
71+
// const token = localStorage.getItem('token');
72+
if (!checkAuth()) {
73+
router.push('/login');
74+
}
75+
}, []);
6976
useEffect(() => {
7077
// Fetch form schema from API and set it in state.
7178
const fetchData = async () => {

apps/learner-web-app/src/components/UserProfileCard/UserProfileCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ const UserProfileCard = () => {
187187
};
188188

189189
return (
190-
<Box>
190+
<Box sx={{ overflowWrap: 'break-word', wordBreak: 'break-word' }}>
191191
<Box
192192
sx={{
193193
background: 'linear-gradient(to bottom, #FFFDF6, #F8EFDA)',

apps/learner-web-app/src/utils/helper.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,30 @@ export const maskMobileNumber = (mobile: string) => {
195195
return first + masked + last;
196196
}
197197
};
198+
export const preserveLocalStorage = () => {
199+
const keysToKeep = [
200+
'preferredLanguage',
201+
'mui-mode',
202+
'mui-color-scheme-dark',
203+
'mui-color-scheme-light',
204+
'hasSeenTutorial',
205+
'lang',
206+
];
207+
208+
const valuesToKeep: { [key: string]: any } = {};
209+
210+
keysToKeep.forEach((key: string) => {
211+
const value = localStorage.getItem(key);
212+
if (value !== null) {
213+
valuesToKeep[key] = value;
214+
}
215+
});
216+
217+
localStorage.clear();
218+
219+
keysToKeep.forEach((key: string) => {
220+
if (valuesToKeep[key] !== undefined) {
221+
localStorage.setItem(key, valuesToKeep[key]);
222+
}
223+
});
224+
};

libs/shared-lib-v2/src/lib/context/LanguageContext.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,15 @@ export const LanguageProvider: React.FC<LanguageProviderProps> = ({
6868
// Translate function
6969
const t = useMemo(() => {
7070
return (key: string): string => {
71-
const keys = key.split('.');
71+
const keys = key?.split('.');
7272
let result: any = translations[language];
73-
74-
for (const k of keys) {
75-
if (result?.[k] === undefined) {
76-
return key; // fallback if any level is missing
73+
if (keys) {
74+
for (const k of keys) {
75+
if (result?.[k] === undefined) {
76+
return key; // fallback if any level is missing
77+
}
78+
result = result[k];
7779
}
78-
result = result[k];
7980
}
8081

8182
return typeof result === 'string' ? result : key;

0 commit comments

Comments
 (0)