Skip to content

Commit

Permalink
add create asset and add more button
Browse files Browse the repository at this point in the history
  • Loading branch information
rajku-dev committed Nov 28, 2024
1 parent 29aa629 commit c5312fb
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/components/Facility/AssetCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,11 @@ const AssetCreate = (props: AssetProps) => {
});
};

const handleSubmitAsync = async (form: AssetData, addMore: boolean) => {
const handleSubmitAsync = async (form: AssetData, buttonId: string) => {
setIsLoading(true);

const data: any = {
id: form.id,
name: form.name,
asset_type: AssetType.INTERNAL,
asset_class: form.asset_class || "",
Expand Down Expand Up @@ -328,7 +329,7 @@ const AssetCreate = (props: AssetProps) => {
if (res?.ok) {
Notification.Success({ msg: "Asset created successfully" });
// Handle "Add More" logic if necessary
if (addMore) {
if (buttonId == "create-asset-add-more-button") {
resetFilters();
const pageContainer = window.document.getElementById("pages");
pageContainer?.scroll(0, 0);
Expand Down Expand Up @@ -518,20 +519,24 @@ const AssetCreate = (props: AssetProps) => {
disabled={isLoading}
defaults={initAssetData}
onCancel={handleOnCancel}
onSubmit={async (obj) => {
await handleSubmitAsync(obj, Boolean(assetId));
onSubmit={async (obj, buttonId) => {
await handleSubmitAsync(obj, buttonId);
}}
className="rounded bg-white p-6 transition-all sm:rounded-xl sm:p-12"
noPadding
validate={AssetFormValidator}
submitLabel={assetId ? t("update") : t("create_asset")}
additionalButtons={[
{
type: "submit",
label: t("create_add_more"),
id: "create-asset-add-more-button",
},
]}
additionalButtons={
!assetId
? [
{
type: "submit",
label: t("create_add_more"),
id: "create-asset-add-more-button",
},
]
: []
}
>
{(field) => (
<>
Expand Down

0 comments on commit c5312fb

Please sign in to comment.