WIP: update: adaptations to use the new backend #1

Draft
arthur.wambst wants to merge 21 commits from dev into master
Showing only changes of commit 5855ea4100 - Show all commits

View File

@ -51,31 +51,36 @@ function BulkUsers() {
const handleSubmit = async () => { const handleSubmit = async () => {
try { try {
const response = await axios.post( const response = await axios.post("/api/users", {
"/api/users",
{
users: userData.filter((user: CSVParseType) => user.name !== ""), users: userData.filter((user: CSVParseType) => user.name !== ""),
jiId: parseInt(practical), jiId: parseInt(practical),
}, });
{
responseType: 'blob', // AJOUTER CETTE LIGNE
}
);
if (response.status === 200) { if (response.status === 200) {
// REMPLACER l'alert par ce code : // REMPLACER l'alert par ce code :
const url = window.URL.createObjectURL(new Blob([response.data])); let str = "";
const link = document.createElement('a'); for (let i = 0; i < response.data.successMails.length; i++) {
link.href = url; const mail = response.data.successMails[i];
link.setAttribute('download', `created_users_${new Date().toISOString().split('T')[0]}.csv`); const password = response.data.successPasswd[i];
document.body.appendChild(link); str += `${mail},${password}\n`;
link.click(); }
link.remove(); const url = window.URL.createObjectURL(
window.URL.revokeObjectURL(url); new Blob([str], { type: "text/csv" }),
);
alert('Users succesfully created ! CSV downloaded.'); const link = document.createElement("a");
navigate('/admin/users'); link.href = url;
} link.setAttribute(
"download",
`created_users_${new Date().toISOString().split("T")[0]}.csv`,
);
document.body.appendChild(link);
link.click();
link.remove();
window.URL.revokeObjectURL(url);
alert("Users succesfully created ! CSV downloaded.");
navigate("/admin/users");
}
if (response.status === 202) if (response.status === 202)
{ const url = window.URL.createObjectURL(new Blob([response.data])); { const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a'); const link = document.createElement('a');