WIP: update: adaptations to use the new backend #1
@ -51,30 +51,35 @@ 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++) {
|
||||||
|
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.href = url;
|
||||||
link.setAttribute('download', `created_users_${new Date().toISOString().split('T')[0]}.csv`);
|
link.setAttribute(
|
||||||
|
"download",
|
||||||
|
`created_users_${new Date().toISOString().split("T")[0]}.csv`,
|
||||||
|
);
|
||||||
document.body.appendChild(link);
|
document.body.appendChild(link);
|
||||||
link.click();
|
link.click();
|
||||||
link.remove();
|
link.remove();
|
||||||
window.URL.revokeObjectURL(url);
|
window.URL.revokeObjectURL(url);
|
||||||
|
|
||||||
alert('Users succesfully created ! CSV downloaded.');
|
alert("Users succesfully created ! CSV downloaded.");
|
||||||
navigate('/admin/users');
|
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]));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user