WIP: update: adaptations to use the new backend #1
@ -51,31 +51,36 @@ function BulkUsers() {
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
const response = await axios.post(
|
||||
"/api/users",
|
||||
{
|
||||
const response = await axios.post("/api/users", {
|
||||
users: userData.filter((user: CSVParseType) => user.name !== ""),
|
||||
jiId: parseInt(practical),
|
||||
},
|
||||
{
|
||||
responseType: 'blob', // AJOUTER CETTE LIGNE
|
||||
});
|
||||
|
||||
if (response.status === 200) {
|
||||
// REMPLACER l'alert par ce code :
|
||||
let str = "";
|
||||
for (let i = 0; i < response.data.successMails.length; i++) {
|
||||
const mail = response.data.successMails[i];
|
||||
const password = response.data.successPasswd[i];
|
||||
str += `${mail},${password}\n`;
|
||||
}
|
||||
const url = window.URL.createObjectURL(
|
||||
new Blob([str], { type: "text/csv" }),
|
||||
);
|
||||
const link = document.createElement("a");
|
||||
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 === 200) {
|
||||
// REMPLACER l'alert par ce code :
|
||||
const url = window.URL.createObjectURL(new Blob([response.data]));
|
||||
const link = document.createElement('a');
|
||||
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)
|
||||
{ const url = window.URL.createObjectURL(new Blob([response.data]));
|
||||
const link = document.createElement('a');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user