Begin addign loading state to mutations BOD-134

This commit is contained in:
Patrick Fic
2020-07-22 10:46:34 -07:00
parent 5f2ced9b45
commit 8f8c26af54
8 changed files with 125 additions and 88 deletions

View File

@@ -1,5 +1,5 @@
import { Button, notification } from "antd";
import React from "react";
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import axios from "axios";
import { useMutation } from "@apollo/react-hooks";
@@ -13,9 +13,10 @@ export default function JobsDocumentsDeleteButton({
const { t } = useTranslation();
const [deleteDocument] = useMutation(DELETE_DOCUMENT);
const imagesToDelete = galleryImages.filter((image) => image.isSelected);
const [loading, setLoading] = useState(false);
const handleDelete = () => {
logImEXEvent("job_documents_delete", { count: imagesToDelete.length });
setLoading(true);
imagesToDelete.forEach((image) => {
let timestamp = Math.floor(Date.now() / 1000);
let public_id = image.key;
@@ -65,10 +66,15 @@ export default function JobsDocumentsDeleteButton({
});
});
});
setLoading(false);
};
return (
<Button disabled={imagesToDelete.length < 1} onClick={handleDelete}>
<Button
disabled={imagesToDelete.length < 1}
loading={loading}
onClick={handleDelete}
>
{t("documents.actions.delete")}
</Button>
);