mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
feat: mark specific template as default
This commit is contained in:
@@ -5,6 +5,14 @@ const DeleteBrandingTemplateAlert = React.lazy(
|
||||
() => import('./DeleteBrandingTemplateAlert'),
|
||||
);
|
||||
|
||||
const MarkDefaultBrandingTemplateAlert = React.lazy(
|
||||
() => import('./MarkDefaultBrandingTemplateAlert'),
|
||||
);
|
||||
|
||||
export const BrandingTemplatesAlerts = [
|
||||
{ name: 'branding-template-delete', component: DeleteBrandingTemplateAlert },
|
||||
{
|
||||
name: 'branding-template-mark-default',
|
||||
component: MarkDefaultBrandingTemplateAlert,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import { AppToaster } from '@/components';
|
||||
import { Alert, Intent } from '@blueprintjs/core';
|
||||
import { useAssignPdfTemplateAsDefault } from '@/hooks/query/pdf-templates';
|
||||
|
||||
import withAlertStoreConnect from '@/containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from '@/containers/Alert/withAlertActions';
|
||||
|
||||
import { compose } from '@/utils';
|
||||
|
||||
/**
|
||||
* Mark default branding template alert.
|
||||
*/
|
||||
function MarkDefaultBrandingTemplateAlert({
|
||||
// #ownProps
|
||||
name,
|
||||
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { templateId },
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
const { mutateAsync: assignPdfTemplateAsDefault } =
|
||||
useAssignPdfTemplateAsDefault();
|
||||
|
||||
const handleConfirmDelete = () => {
|
||||
assignPdfTemplateAsDefault({ templateId })
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message:
|
||||
'The branding template has been marked as default successfully.',
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
closeAlert(name);
|
||||
})
|
||||
.catch((error) => {
|
||||
AppToaster.show({
|
||||
message: 'Something went wrong.',
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
closeAlert(name);
|
||||
});
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={intl.get('cancel')}
|
||||
confirmButtonText={'Mark as Default'}
|
||||
intent={Intent.WARNING}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancel}
|
||||
onConfirm={handleConfirmDelete}
|
||||
>
|
||||
<p>
|
||||
Are you sure want to mark the given branding template as default
|
||||
template?
|
||||
</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
)(MarkDefaultBrandingTemplateAlert);
|
||||
Reference in New Issue
Block a user