Skip to content

Commit

Permalink
Enhance error handling and user feedback in ActionButtons component
Browse files Browse the repository at this point in the history
  • Loading branch information
malak-elbanna committed Mar 15, 2024
1 parent 8250d3e commit 4c1bb48
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/components/action-buttons/action-buttons.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ function ActionButtons({ schema, t }: ActionButtonsProps) {
const { form, mutate } = useForm(formUuid);
const [status, setStatus] = useState<Status>('idle');
const [showUnpublishModal, setShowUnpublishModal] = useState(false);
const [showError, setShowError] = useState(false);
const [errorMessage, setErrorMessage] = useState('');

const launchUnpublishModal = () => {
setShowUnpublishModal(true);
};

async function handlePublish() {
setStatus('publishing');
setShowError(false);
try {
await publishForm(form.uuid);

Expand All @@ -49,6 +52,8 @@ function ActionButtons({ schema, t }: ActionButtonsProps) {
subtitle: error?.message,
});
setStatus('error');
setShowError(true);
setErrorMessage(error.message);
}
}
}
Expand Down Expand Up @@ -86,6 +91,17 @@ function ActionButtons({ schema, t }: ActionButtonsProps) {
<SaveFormModal form={form} schema={schema} />

<>
{/* Error message display */}
{showError && (
<div className={styles.errorMessage}>
<p>{errorMessage}</p>
{/* Retry button */}
<Button kind="secondary" onClick={handlePublish}>
{t('retry', 'Retry')}
</Button>
</div>
)}

{form && !form.published ? (
<Button kind="secondary" onClick={handlePublish} disabled={status === 'publishing'}>
{status === 'publishing' && !form?.published ? (
Expand Down

0 comments on commit 4c1bb48

Please sign in to comment.