diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json index b43c70a..621d435 100644 --- a/client/public/locales/en/common.json +++ b/client/public/locales/en/common.json @@ -227,6 +227,9 @@ "list": "Vendors", "show": "Show Vendor", "show_title": "[Vendor #{{id}}] {{name}}" + }, + "form": { + "vendor_updated": "This vendor has been updated by someone/something else since you opened this page. Saving will overwrite those changes!" } }, "table": { diff --git a/client/src/pages/vendors/edit.tsx b/client/src/pages/vendors/edit.tsx index 5060733..8f84548 100644 --- a/client/src/pages/vendors/edit.tsx +++ b/client/src/pages/vendors/edit.tsx @@ -1,18 +1,28 @@ -import React from "react"; +import React, { useState } from "react"; import { IResourceComponentsProps, useTranslate } from "@refinedev/core"; import { Edit, useForm } from "@refinedev/antd"; -import { Form, Input, DatePicker } from "antd"; +import { Form, Input, DatePicker, message, Alert } from "antd"; import dayjs from "dayjs"; import TextArea from "antd/es/input/TextArea"; import { IVendor } from "./model"; export const VendorEdit: React.FC = () => { const t = useTranslate(); + const [messageApi, contextHolder] = message.useMessage(); + const [hasChanged, setHasChanged] = useState(false); - const { formProps, saveButtonProps } = useForm(); + const { formProps, saveButtonProps } = useForm({ + liveMode: "manual", + onLiveEvent() { + // Warn the user if the vendor has been updated since the form was opened + messageApi.warning(t("vendor.form.vendor_updated")); + setHasChanged(true); + }, + }); return ( + {contextHolder}
= () => {