mirror of
https://github.com/formbricks/formbricks.git
synced 2026-05-06 22:02:04 -05:00
fix: isDirty changes with react hook form
This commit is contained in:
+8
-7
@@ -38,8 +38,8 @@ export const EditProductNameForm: React.FC<EditProductNameProps> = ({
|
||||
});
|
||||
|
||||
const { errors, isDirty } = form.formState;
|
||||
const nameError = errors.name?.message;
|
||||
|
||||
const nameError = errors.name?.message;
|
||||
const isSubmitting = form.formState.isSubmitting;
|
||||
|
||||
const updateProduct: SubmitHandler<TEditProductName> = async (data) => {
|
||||
@@ -50,11 +50,6 @@ export const EditProductNameForm: React.FC<EditProductNameProps> = ({
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isDirty) {
|
||||
form.setError("name", { type: "manual", message: "Product name is the same" }, { shouldFocus: true });
|
||||
return;
|
||||
}
|
||||
|
||||
const updatedProduct = await updateProductAction(environmentId, product.id, { name });
|
||||
|
||||
if (isProductNameEditDisabled) {
|
||||
@@ -65,6 +60,7 @@ export const EditProductNameForm: React.FC<EditProductNameProps> = ({
|
||||
if (!!updatedProduct?.id) {
|
||||
toast.success("Product name updated successfully.");
|
||||
router.refresh();
|
||||
form.resetField("name", { defaultValue: updatedProduct.name });
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
@@ -99,7 +95,12 @@ export const EditProductNameForm: React.FC<EditProductNameProps> = ({
|
||||
)}
|
||||
/>
|
||||
|
||||
<Button type="submit" variant="darkCTA" size="sm" loading={isSubmitting} disabled={isSubmitting}>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="darkCTA"
|
||||
size="sm"
|
||||
loading={isSubmitting}
|
||||
disabled={isSubmitting || !isDirty}>
|
||||
Update
|
||||
</Button>
|
||||
</Form>
|
||||
|
||||
+9
-11
@@ -33,23 +33,15 @@ export const EditWaitingTimeForm: React.FC<EditWaitingTimeProps> = ({ product, e
|
||||
mode: "onChange",
|
||||
});
|
||||
|
||||
const { isDirty } = form.formState;
|
||||
const { isDirty, isSubmitting } = form.formState;
|
||||
|
||||
const updateWaitingTime: SubmitHandler<EditWaitingTimeFormValues> = async (data) => {
|
||||
if (!isDirty) {
|
||||
form.setError(
|
||||
"recontactDays",
|
||||
{ type: "manual", message: "Waiting period is the same" },
|
||||
{ shouldFocus: true }
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const updatedProduct = await updateProductAction(environmentId, product.id, data);
|
||||
if (!!updatedProduct?.id) {
|
||||
toast.success("Waiting period updated successfully.");
|
||||
router.refresh();
|
||||
form.resetField("recontactDays", { defaultValue: updatedProduct.recontactDays });
|
||||
}
|
||||
} catch (err) {
|
||||
toast.error(`Error: ${err.message}`);
|
||||
@@ -87,7 +79,13 @@ export const EditWaitingTimeForm: React.FC<EditWaitingTimeProps> = ({ product, e
|
||||
)}
|
||||
/>
|
||||
|
||||
<Button type="submit" variant="darkCTA" size="sm" className="w-fit">
|
||||
<Button
|
||||
type="submit"
|
||||
variant="darkCTA"
|
||||
size="sm"
|
||||
className="w-fit"
|
||||
loading={isSubmitting}
|
||||
disabled={isSubmitting || !isDirty}>
|
||||
Update
|
||||
</Button>
|
||||
</Form>
|
||||
|
||||
Reference in New Issue
Block a user