mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 16:03:21 +00:00
refactor: refactoring du FRONT page subscribe
This commit is contained in:
@ -1,39 +0,0 @@
|
||||
|
||||
import {
|
||||
BK_LOGIN_URL,
|
||||
FR_USERS_LOGIN_URL ,
|
||||
FR_ADMIN_HOME_URL,
|
||||
FR_ADMIN_SUBSCRIPTIONS_URL,
|
||||
FR_ADMIN_CLASSES_URL,
|
||||
FR_ADMIN_GRADES_URL,
|
||||
FR_ADMIN_PLANNING_URL,
|
||||
FR_ADMIN_TEACHERS_URL,
|
||||
FR_ADMIN_SETTINGS_URL
|
||||
} from '@/utils/Url';
|
||||
|
||||
import {mockUser} from "@/data/mockUsersData";
|
||||
|
||||
const useFakeData = process.env.NEXT_PUBLIC_USE_FAKE_DATA === 'true';
|
||||
|
||||
|
||||
/**
|
||||
* Disconnects the user after confirming the action.
|
||||
* If `NEXT_PUBLIC_USE_FAKE_DATA` environment variable is set to 'true', it will log a fake disconnect and redirect to the login URL.
|
||||
* Otherwise, it will send a PUT request to the backend to update the user profile and then redirect to the login URL.
|
||||
*
|
||||
* @function
|
||||
* @name disconnect
|
||||
* @returns {void}
|
||||
*/
|
||||
export function disconnect () {
|
||||
if (confirm("\nÊtes-vous sûr(e) de vouloir vous déconnecter ?")) {
|
||||
|
||||
if (useFakeData) {
|
||||
console.log('Fake disconnect:', mockUser);
|
||||
router.push(`${FR_USERS_LOGIN_URL}`);
|
||||
} else {
|
||||
console.log('Fake disconnect:', mockUser);
|
||||
router.push(`${FR_USERS_LOGIN_URL}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
67
Front-End/src/app/lib/authAction.js
Normal file
67
Front-End/src/app/lib/authAction.js
Normal file
@ -0,0 +1,67 @@
|
||||
|
||||
import {
|
||||
BE_AUTH_LOGIN_URL,
|
||||
BE_AUTH_PROFILE_URL,
|
||||
FE_USERS_LOGIN_URL ,
|
||||
} from '@/utils/Url';
|
||||
|
||||
import {mockUser} from "@/data/mockUsersData";
|
||||
|
||||
const useFakeData = process.env.NEXT_PUBLIC_USE_FAKE_DATA === 'true';
|
||||
|
||||
|
||||
/**
|
||||
* Disconnects the user after confirming the action.
|
||||
* If `NEXT_PUBLIC_USE_FAKE_DATA` environment variable is set to 'true', it will log a fake disconnect and redirect to the login URL.
|
||||
* Otherwise, it will send a PUT request to the backend to update the user profile and then redirect to the login URL.
|
||||
*
|
||||
* @function
|
||||
* @name disconnect
|
||||
* @returns {void}
|
||||
*/
|
||||
export const disconnect = () => {
|
||||
if (confirm("\nÊtes-vous sûr(e) de vouloir vous déconnecter ?")) {
|
||||
|
||||
if (useFakeData) {
|
||||
console.log('Fake disconnect:', mockUser);
|
||||
router.push(`${FE_USERS_LOGIN_URL}`);
|
||||
} else {
|
||||
console.log('Fake disconnect:', mockUser);
|
||||
router.push(`${FE_USERS_LOGIN_URL}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const createProfile = (data,csrfToken) => {
|
||||
const request = new Request(
|
||||
`${BE_AUTH_PROFILE_URL}`,
|
||||
{
|
||||
method:'POST',
|
||||
headers: {
|
||||
'Content-Type':'application/json',
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(data),
|
||||
}
|
||||
);
|
||||
return fetch(request).then(response => response.json())
|
||||
}
|
||||
|
||||
|
||||
export const updateProfile = (id, data, csrfToken) => {
|
||||
const request = new Request(
|
||||
`${BE_AUTH_PROFILE_URL}/${id}`,
|
||||
{
|
||||
method:'PUT',
|
||||
headers: {
|
||||
'Content-Type':'application/json',
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(data),
|
||||
}
|
||||
);
|
||||
return fetch(request).then(response => response.json())
|
||||
}
|
||||
9
Front-End/src/app/lib/schoolAction.js
Normal file
9
Front-End/src/app/lib/schoolAction.js
Normal file
@ -0,0 +1,9 @@
|
||||
import {
|
||||
BE_SCHOOL_SCHOOLCLASSES_URL
|
||||
} from '@/utils/Url';
|
||||
|
||||
export const fetchClasses = () => {
|
||||
return fetch(`${BE_SCHOOL_SCHOOLCLASSES_URL}`)
|
||||
.then(response => response.json())
|
||||
|
||||
};
|
||||
123
Front-End/src/app/lib/subscriptionAction.js
Normal file
123
Front-End/src/app/lib/subscriptionAction.js
Normal file
@ -0,0 +1,123 @@
|
||||
import {
|
||||
BE_SUBSCRIPTION_STUDENTS_URL,
|
||||
BE_SUBSCRIPTION_ARCHIVE_URL,
|
||||
BE_SUBSCRIPTION_SEND_URL,
|
||||
BE_SUBSCRIPTION_REGISTERFORM_URL,
|
||||
BE_SUBSCRIPTION_REGISTERFORMS_URL,
|
||||
BE_SUBSCRIPTION_REGISTERFORMFILE_TEMPLATE_URL
|
||||
} from '@/utils/Url';
|
||||
|
||||
export const PENDING = 'pending';
|
||||
export const SUBSCRIBED = 'subscribed';
|
||||
export const ARCHIVED = 'archived';
|
||||
|
||||
|
||||
export const fetchRegisterForm = (type=PENDING, page='', pageSize='', search = '') => {
|
||||
let url = `${BE_SUBSCRIPTION_REGISTERFORMS_URL}/${type}`;
|
||||
if (page !== '' && pageSize !== '') {
|
||||
url = `${BE_SUBSCRIPTION_REGISTERFORMS_URL}/${type}?page=${page}&search=${search}`;
|
||||
}
|
||||
return fetch(url, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}).then(response => response.json())
|
||||
};
|
||||
|
||||
export const editRegisterForm=(id, data, csrfToken)=>{
|
||||
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTERFORM_URL}/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
credentials: 'include'
|
||||
})
|
||||
.then(response => response.json())
|
||||
|
||||
};
|
||||
|
||||
export const createRegisterForm=(data, csrfToken)=>{
|
||||
const url = `${BE_SUBSCRIPTION_REGISTERFORM_URL}`;
|
||||
return fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
credentials: 'include'
|
||||
})
|
||||
.then(response => response.json())
|
||||
}
|
||||
|
||||
export const archiveRegisterForm = (id) => {
|
||||
const url = `${BE_SUBSCRIPTION_ARCHIVE_URL}/${id}`;
|
||||
return fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}).then(response => response.json())
|
||||
}
|
||||
|
||||
export const sendRegisterForm = (id) => {
|
||||
const url = `${BE_SUBSCRIPTION_SEND_URL}/${id}`;
|
||||
return fetch(url, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}).then(response => response.json())
|
||||
|
||||
}
|
||||
|
||||
export const fetchRegisterFormFileTemplate = () => {
|
||||
const request = new Request(
|
||||
`${BE_SUBSCRIPTION_REGISTERFORMFILE_TEMPLATE_URL}`,
|
||||
{
|
||||
method:'GET',
|
||||
headers: {
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
}
|
||||
);
|
||||
return fetch(request).then(response => response.json())
|
||||
};
|
||||
|
||||
export const createRegisterFormFileTemplate = (data,csrfToken) => {
|
||||
|
||||
fetch(`${BE_SUBSCRIPTION_REGISTERFORMFILE_TEMPLATE_URL}`, {
|
||||
method: 'POST',
|
||||
body: data,
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
.then(response => response.json())
|
||||
}
|
||||
|
||||
export const deleteRegisterFormFileTemplate = (fileId,csrfToken) => {
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTERFORMFILE_TEMPLATE_URL}/${fileId}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
}
|
||||
export const fetchStudents = () => {
|
||||
const request = new Request(
|
||||
`${BE_SUBSCRIPTION_STUDENTS_URL}`,
|
||||
{
|
||||
method:'GET',
|
||||
headers: {
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
}
|
||||
);
|
||||
return fetch(request).then(response => response.json())
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user