Browse Source

支持 pr 修改

visuddhinanda 2 năm trước cách đây
mục cha
commit
b344a98881
1 tập tin đã thay đổi với 49 bổ sung22 xóa
  1. 49 22
      dashboard/src/components/template/SentEdit/SentCellEditable.tsx

+ 49 - 22
dashboard/src/components/template/SentEdit/SentCellEditable.tsx

@@ -67,6 +67,7 @@ export const sentSave = (
 interface IWidget {
   data: ISentence;
   isPr?: boolean;
+  isCreatePr?: boolean;
   onSave?: Function;
   onClose?: Function;
   onCreate?: Function;
@@ -77,6 +78,7 @@ const SentCellEditableWidget = ({
   onClose,
   onCreate,
   isPr = false,
+  isCreatePr = false,
 }: IWidget) => {
   const intl = useIntl();
   const [value, setValue] = useState(data.content);
@@ -94,31 +96,56 @@ const SentCellEditableWidget = ({
     if (!value) {
       return;
     }
-    post<ISentencePrRequest, ISentencePrResponse>(`/v2/sentpr`, {
-      book: data.book,
-      para: data.para,
-      begin: data.wordStart,
-      end: data.wordEnd,
-      channel: data.channel.id,
-      text: value,
-    })
-      .then((json) => {
-        setSaving(false);
+    if (isCreatePr) {
+      post<ISentencePrRequest, ISentencePrResponse>(`/v2/sentpr`, {
+        book: data.book,
+        para: data.para,
+        begin: data.wordStart,
+        end: data.wordEnd,
+        channel: data.channel.id,
+        text: value,
+      })
+        .then((json) => {
+          setSaving(false);
 
-        if (json.ok) {
-          message.success(intl.formatMessage({ id: "flashes.success" }));
-          if (typeof onCreate !== "undefined") {
-            onCreate();
+          if (json.ok) {
+            message.success(intl.formatMessage({ id: "flashes.success" }));
+            if (typeof onCreate !== "undefined") {
+              onCreate();
+            }
+          } else {
+            message.error(json.message);
           }
-        } else {
-          message.error(json.message);
-        }
+        })
+        .catch((e) => {
+          setSaving(false);
+          console.error("catch", e);
+          message.error(e.message);
+        });
+    } else {
+      const url = `/v2/sentpr/${data.id}`;
+      console.log("url", url);
+      put<ISentencePrRequest, ISentencePrResponse>(url, {
+        text: value,
       })
-      .catch((e) => {
-        setSaving(false);
-        console.error("catch", e);
-        message.error(e.message);
-      });
+        .then((json) => {
+          if (json.ok) {
+            message.success(intl.formatMessage({ id: "flashes.success" }));
+            if (typeof onSave !== "undefined") {
+              onSave();
+            }
+          } else {
+            message.error(json.message);
+          }
+        })
+        .finally(() => {
+          setSaving(false);
+        })
+        .catch((e) => {
+          console.error("catch", e);
+          message.error(e.message);
+        });
+    }
   };
 
   const save = () => {