mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 01:01:49 +10:00
feat: ux improvements
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
@ -73,6 +73,7 @@ export const AddSubjectFormPartial = ({
|
|||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
);
|
);
|
||||||
|
const [showUndoButton, setShowUndoButton] = useState(false);
|
||||||
|
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@ -94,25 +95,29 @@ export const AddSubjectFormPartial = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const handleOnBlur = async (field: 'subject' | 'message', value: string) => {
|
const handleOnBlur = async (field: 'subject' | 'message', value: string) => {
|
||||||
try {
|
if (value !== oldEmailData?.[field]) {
|
||||||
await setEmailSettingsForDocument({
|
try {
|
||||||
documentId: document.id,
|
await setEmailSettingsForDocument({
|
||||||
[field]: value,
|
documentId: document.id,
|
||||||
});
|
[field]: value,
|
||||||
|
});
|
||||||
|
|
||||||
router.refresh();
|
router.refresh();
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: 'Email settings updated',
|
title: 'Email settings updated',
|
||||||
description: `The email settings for the document have been updated.`,
|
description: 'The email settings for the document have been updated.',
|
||||||
});
|
duration: 5000,
|
||||||
} catch (e) {
|
});
|
||||||
console.error(e);
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: 'Error',
|
title: 'Error',
|
||||||
description: 'An error occurred while updating the email settings.',
|
description: 'An error occurred while updating the email settings.',
|
||||||
});
|
duration: 5000,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -134,6 +139,7 @@ export const AddSubjectFormPartial = ({
|
|||||||
toast({
|
toast({
|
||||||
title: 'Changes reverted',
|
title: 'Changes reverted',
|
||||||
description: 'The latest change has been reverted to the original value.',
|
description: 'The latest change has been reverted to the original value.',
|
||||||
|
duration: 5000,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -141,10 +147,25 @@ export const AddSubjectFormPartial = ({
|
|||||||
toast({
|
toast({
|
||||||
title: 'Error',
|
title: 'Error',
|
||||||
description: 'An error occurred while undoing the latest change.',
|
description: 'An error occurred while undoing the latest change.',
|
||||||
|
duration: 5000,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (oldEmailData) {
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
setShowUndoButton(false);
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
setShowUndoButton(true);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, [oldEmailData]);
|
||||||
|
|
||||||
const onFormSubmit = handleSubmit(onSubmit);
|
const onFormSubmit = handleSubmit(onSubmit);
|
||||||
const { currentStep, totalSteps, previousStep } = useStep();
|
const { currentStep, totalSteps, previousStep } = useStep();
|
||||||
|
|
||||||
@ -204,8 +225,7 @@ export const AddSubjectFormPartial = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Hide the button after 5 seconds */}
|
{showUndoButton && oldEmailData && (
|
||||||
{oldEmailData && (
|
|
||||||
<Button onClick={() => void handleUndoButton()}>Undo latest change</Button>
|
<Button onClick={() => void handleUndoButton()}>Undo latest change</Button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user