From 244bd2ab78dd104456370bbad7dbd3cd02c8c449 Mon Sep 17 00:00:00 2001
From: Niraj Raut <84171890+nirajkumar999@users.noreply.github.com>
Date: Tue, 6 Aug 2024 20:04:32 +0530
Subject: [PATCH 1/9] Refactored LinksForm component. Prevent unnecessary form
submission on button click. (#5891)
We can extend the performance optimization by preventing unnecessary onSubmit of Form in case of tnc, privacy policy and help center fields. So PATCH request will only be sent if there is actual change in the value.
I have introduced a useRef variable formText which initially stores the actual value of these fields and further tracks any changes to the value.
In handleSubmit function we call mutation only when this formText variable shows any changes. Hence this way we prevent any unnecessary PATCH request when user continuously clicks the Change URL function.
---
.../administration/LinksForm.jsx | 23 +++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/app/javascript/components/admin/site_settings/administration/LinksForm.jsx b/app/javascript/components/admin/site_settings/administration/LinksForm.jsx
index b92aa3680c..ce500ede70 100644
--- a/app/javascript/components/admin/site_settings/administration/LinksForm.jsx
+++ b/app/javascript/components/admin/site_settings/administration/LinksForm.jsx
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License along
// with Greenlight; if not, see