From 2dfd725ee005cb2a70a37a217430e081fcd41985 Mon Sep 17 00:00:00 2001
From: GyDi <segydi@foxmail.com>
Date: Sun, 13 Feb 2022 19:40:31 +0800
Subject: [PATCH] fix: reset value correctly

---
 src/components/profile/profile-new.tsx | 9 ++++++++-
 src/pages/profiles.tsx                 | 2 +-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/components/profile/profile-new.tsx b/src/components/profile/profile-new.tsx
index bd2a5e8..336432b 100644
--- a/src/components/profile/profile-new.tsx
+++ b/src/components/profile/profile-new.tsx
@@ -1,4 +1,4 @@
-import { useState } from "react";
+import { useEffect, useState } from "react";
 import {
   Button,
   Dialog,
@@ -28,6 +28,13 @@ const ProfileNew = (props: Props) => {
     onSubmit(name, desc);
   };
 
+  useEffect(() => {
+    if (!open) {
+      setName("");
+      setDesc("");
+    }
+  }, [open]);
+
   return (
     <Dialog open={open} onClose={onClose}>
       <DialogTitle>Create Profile</DialogTitle>
diff --git a/src/pages/profiles.tsx b/src/pages/profiles.tsx
index 3f75eb0..4996df2 100644
--- a/src/pages/profiles.tsx
+++ b/src/pages/profiles.tsx
@@ -104,8 +104,8 @@ const ProfilePage = () => {
 
     try {
       await newProfile(name, desc);
-      mutate("getProfiles");
       setDialogOpen(false);
+      mutate("getProfiles");
     } catch (err: any) {
       err && Notice.error(err.toString());
     } finally {
-- 
GitLab