Skip to content

Commit

Permalink
Merge pull request #511 from shreyas1434shinde/InAppNotification
Browse files Browse the repository at this point in the history
new course card assets added
  • Loading branch information
itsvick authored Dec 10, 2024
2 parents deafd66 + 43ce983 commit bcc09d9
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 35 deletions.
Binary file added src/assets/images/Unit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/bgUnit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/bgh5p.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/h5p.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 52 additions & 31 deletions src/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { useDirection } from '../hooks/useDirection';
import { login } from '../services/LoginService';
import { getUserDetails, getUserId } from '../services/ProfileService';
import loginImg from './../assets/images/login-image.jpg';
import { UpdateDeviceNotification } from '@/services/NotificationService';

const LoginPage = () => {
const { t, i18n } = useTranslation();
Expand Down Expand Up @@ -194,73 +195,95 @@ const LoginPage = () => {

const handleFormSubmit = async (event: React.FormEvent) => {
event.preventDefault();

logEvent({
action: 'login-button-clicked',
category: 'Login Page',
label: 'Login Button Clicked',
});

if (!usernameError && !passwordError) {
setLoading(true);

try {
const response = await login({
username: username,
password: password,
});
const response = await login({ username, password });

if (response?.result?.access_token) {
if (typeof window !== 'undefined' && window.localStorage) {
const token = response.result.access_token;
const refreshToken = response?.result?.refresh_token;

if (token) {
localStorage.setItem('token', token);
}
rememberMe
? localStorage.setItem('refreshToken', refreshToken)
: localStorage.removeItem('refreshToken');

if (rememberMe) {
localStorage.setItem('refreshToken', refreshToken);
} else {
localStorage.removeItem('refreshToken');
}

const userResponse = await getUserId();
const activeSessionId = await getAcademicYearList();
localStorage.setItem('userId', userResponse?.userId);
setUserId(userResponse?.userId);
const userId = userResponse?.userId;

localStorage.setItem('userId', userId);
setUserId(userId);

if (token && userResponse?.userId) {
if (token && userId) {
document.cookie = `authToken=${token}; path=/; secure; SameSite=Strict`;
document.cookie = `userId=${userResponse.userId}; path=/; secure; SameSite=Strict`;
document.cookie = `userId=${userId}; path=/; secure; SameSite=Strict`;

// Retrieve deviceID from local storage
const deviceID = localStorage.getItem('deviceID');

if (deviceID) {
try {
// Update device notification
const headers = {
tenantId: userResponse?.tenantData[0]?.tenantId,
Authorization: `Bearer ${token}`,
};

const updateResponse = await UpdateDeviceNotification(
{ deviceId: deviceID },
userId,
headers
);

console.log('Device notification updated successfully:', updateResponse);
} catch (updateError) {
console.error('Error updating device notification:', updateError);
}
}
}

logEvent({
action: 'login-success',
category: 'Login Page',
label: 'Login Success',
value: userResponse?.userId,
value: userId,
});

localStorage.setItem('role', userResponse?.tenantData[0]?.roleName);
localStorage.setItem('userEmail', userResponse?.email);
localStorage.setItem('userName', userResponse?.name);
localStorage.setItem('userId', userResponse?.userId);
localStorage.setItem('userIdName', userResponse?.username);
localStorage.setItem(
'temporaryPassword',
userResponse?.temporaryPassword ?? 'false'
);

setUserRole(userResponse?.tenantData[0]?.roleName);
setAccessToken(token);

const userDetails = await getUserDetails(
userResponse?.userId,
true
);
const userDetails = await getUserDetails(userId, true);
if (userDetails?.result?.userData) {
const customFields = userDetails?.result?.userData?.customFields;
if (customFields?.length) {
const state = customFields.find(
(field: any) => field?.label === 'STATES'
);
const district = customFields.find(
(field: any) => field?.label === 'DISTRICTS'
);
const block = customFields.find(
(field: any) => field?.label === 'BLOCKS'
);
const state = customFields.find((field: any) => field?.label === 'STATES');
const district = customFields.find((field: any) => field?.label === 'DISTRICTS');
const block = customFields.find((field: any) => field?.label === 'BLOCKS');

if (state) {
localStorage.setItem('stateName', state?.value);
Expand All @@ -287,8 +310,8 @@ const LoginPage = () => {
}
console.log('userDetails', userDetails);
}
setLoading(false);
}
setLoading(false);
} else if (response?.responseCode === 404) {
handleInvalidUsernameOrPassword();
setLoading(false);
Expand All @@ -300,15 +323,13 @@ const LoginPage = () => {
handleInvalidUsernameOrPassword();
} else {
console.error('Error:', error);
showToastMessage(
t('LOGIN_PAGE.USERNAME_PASSWORD_NOT_CORRECT'),
'error'
);
showToastMessage(t('LOGIN_PAGE.USERNAME_PASSWORD_NOT_CORRECT'), 'error');
}
}
}
};


const isButtonDisabled =
!username || !password || usernameError || passwordError;

Expand Down
2 changes: 1 addition & 1 deletion src/pages/logout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Logout() {
'mui-color-scheme-dark',
'mui-color-scheme-light',
'hasSeenTutorial',
'deviceID',
// 'deviceID',
];
// Retrieve the values of the keys to keep
const valuesToKeep: { [key: string]: any } = {};
Expand Down
12 changes: 9 additions & 3 deletions src/utils/app.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import html from '../assets/images/HTML.svg';
import mp4 from '../assets/images/MP4.svg';
import qml from '../assets/images/Qml.svg';
import youtube from '../assets/images/youtube.svg';
import h5p from '../assets/images/h5p.png'
import unit from '../assets/images/Unit.png'


// background image

Expand All @@ -15,6 +18,9 @@ import bghtml from '../assets/images/bgHtml.svg';
import bgmp4 from '../assets/images/bgMP4 .svg';
import bgqml from '../assets/images/bgQml.svg';
import bgyoutube from '../assets/images/bgYouTube.svg';
import bgh5p from '../assets/images/bgh5p.png'
import bgunit from '../assets/images/bgUnit.png'


export const limit: number = 300;
export const refetchInterval: number = 5 * 60 * 1000; // 5 min
Expand Down Expand Up @@ -226,7 +232,7 @@ export const ContentCardsTypes: FileType = {
imgPath: qml,
BgImgPath: bgqml,
},
[ContentType.H5P]: { name: 'H5P', imgPath: html, BgImgPath: bghtml },
[ContentType.H5P]: { name: 'H5P', imgPath: h5p, BgImgPath: bgh5p },
[ContentType.YOUTUBE_X_VIDEO]: {
name: 'YouTube',
imgPath: youtube,
Expand All @@ -240,8 +246,8 @@ export const ContentCardsTypes: FileType = {
[ContentType.WEBM_VIDEO]: { name: 'WEBM', imgPath: mp4, BgImgPath: bgmp4 },
[ContentType.COLLECTION]: {
name: 'Course',
imgPath: html,
BgImgPath: bghtml,
imgPath: unit,
BgImgPath: bgunit,
},
};

Expand Down

0 comments on commit bcc09d9

Please sign in to comment.