From 886519e3b40d7945943aef6aaa14a4b78e118f97 Mon Sep 17 00:00:00 2001 From: Donkie Date: Sun, 15 Oct 2023 21:35:49 +0200 Subject: [PATCH] Added live updates to filaments in client --- client/public/locales/en/common.json | 3 ++ client/src/pages/filaments/edit.tsx | 17 ++++++++++-- client/src/pages/filaments/list.tsx | 41 ++++++++++++++++++++-------- client/src/pages/filaments/show.tsx | 4 ++- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json index 1f4a4c5..b43c70a 100644 --- a/client/public/locales/en/common.json +++ b/client/public/locales/en/common.json @@ -207,6 +207,9 @@ "list": "Filaments", "show": "Show Filament", "show_title": "[Filament #{{id}}] {{name}}" + }, + "form": { + "filament_updated": "This filament has been updated by someone/something else since you opened this page. Saving will overwrite those changes!" } }, "vendor": { diff --git a/client/src/pages/filaments/edit.tsx b/client/src/pages/filaments/edit.tsx index c8ab0c6..8b44a6f 100644 --- a/client/src/pages/filaments/edit.tsx +++ b/client/src/pages/filaments/edit.tsx @@ -1,7 +1,7 @@ -import React from "react"; +import React, { useState } from "react"; import { IResourceComponentsProps, useTranslate } from "@refinedev/core"; import { Edit, useForm, useSelect } from "@refinedev/antd"; -import { Form, Input, DatePicker, Select, InputNumber, ColorPicker } from "antd"; +import { Form, Input, DatePicker, Select, InputNumber, ColorPicker, message, Alert } from "antd"; import dayjs from "dayjs"; import TextArea from "antd/es/input/TextArea"; import { numberFormatter, numberParser } from "../../utils/parsing"; @@ -10,8 +10,17 @@ import { IFilament } from "./model"; export const FilamentEdit: 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 filament has been updated since the form was opened + messageApi.warning(t("filament.form.filament_updated")); + setHasChanged(true); + }, + }); const { selectProps } = useSelect({ resource: "vendor", @@ -24,6 +33,7 @@ export const FilamentEdit: React.FC = () => { return ( + {contextHolder}
= () => {