social_media_app icon indicating copy to clipboard operation
social_media_app copied to clipboard

user is sending update post request even there is no change in any fields

Open Vs-kishu opened this issue 1 year ago • 2 comments

    if (post && action === 'Update') {
      const updatedPost = await updatePost({
        ...value,
        postId: post.$id,
        imageId: post.imageId,
        imageUrl: post.imageUrl,
      });
      if (!updatedPost) {
        return toast({ title: 'please try again' });
      }
      return navigate(`/posts/${post.$id}`);
    }
    const newPost = await createPost({ ...value, userId: user.id });
    if (!newPost) {
      toast({
        title: `${action} post failed. Please try again.`,
      });
    }
    navigate('/');
  };

Vs-kishu avatar Nov 05 '23 05:11 Vs-kishu

look at My function I am doing same thing useEffect(() => { if (form.formState.isDirty) { setFileChanged(true); } else { setFileChanged(false); } }, [form.formState.isDirty]);

Using this use Effect we can disabled the update post button so that user cannot click the update button for the API request even he/she not updated any field

Vs-kishu avatar Nov 07 '23 03:11 Vs-kishu

look at My function I am doing same thing useEffect(() => { if (form.formState.isDirty) { setFileChanged(true); } else { setFileChanged(false); } }, [form.formState.isDirty]);

Using this use Effect we can disabled the update post button so that user cannot click the update button for the API request even he/she not updated any field

What does your form look like?

hmongdev avatar Nov 07 '23 16:11 hmongdev