Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add customize templates button to edit forms #708

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/webapp/src/components/PageForm/PageForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ PageFormFooter.displayName = 'PageFormFooter';
const footerActionsStyle = `
width: 100%;
background: #fff;
padding: 14px 18px;
padding: 14px 20px;
border-top: 1px solid rgb(210, 221, 226);
box-shadow: 0px -1px 4px 0px rgba(0, 0, 0, 0.05);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button } from '@blueprintjs/core';
import { Button, ButtonProps } from '@blueprintjs/core';
import styled from 'styled-components';
import { FFormGroup } from '@/components';
import { FFormGroup, Icon } from '@/components';

export const BrandingThemeFormGroup = styled(FFormGroup)`
margin-bottom: 0;
Expand All @@ -14,33 +14,21 @@ export const BrandingThemeFormGroup = styled(FFormGroup)`
}
`;

export const BrandingThemeSelectButton = styled(Button)`
position: relative;
padding-right: 26px;

&::after {
content: '';
display: inline-block;
width: 0;
height: 0;

border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-top: 5px solid #98a1ae;

position: absolute;
right: -2px;
top: 50%;
margin-top: -2px;
margin-right: 12px;
border-radius: 1px;
}
`;


export const convertBrandingTemplatesToOptions = (brandingTemplates: Array<any>) => {
export const BrandingThemeSelectButton = (props: ButtonProps) => {
return (
<Button
text={props?.text || 'Brand Theme'}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
minimal
{...props}
/>
);
};

export const convertBrandingTemplatesToOptions = (
brandingTemplates: Array<any>,
) => {
return brandingTemplates?.map(
(template) =>
({ text: template.template_name, value: template.id } || []),
)
}
(template) => ({ text: template.template_name, value: template.id } || []),
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function StripePaymentMethod() {
</Menu>
}
>
<Button small icon={<MoreIcon size={16} />} />
<Button small icon={<MoreIcon height={10} width={10} />} />
</Popover>
)}
</Group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ import {
BrandingThemeSelectButton,
} from '@/containers/BrandingTemplates/BrandingTemplatesSelectFields';
import { useCreditNoteFormBrandingTemplatesOptions } from './utils';
import { MoreIcon } from '@/icons/More';
import { useDrawerActions } from '@/hooks/state';
import { DRAWERS } from '@/constants/drawers';

/**
* Credit note floating actions.
*/
export default function CreditNoteFloatingActions() {
const history = useHistory();
const { openDrawer } = useDrawerActions();

// Formik context.
const { resetForm, submitForm, isSubmitting } = useFormikContext();
Expand Down Expand Up @@ -84,6 +88,11 @@ export default function CreditNoteFloatingActions() {
resetForm();
};

// Handles the credit note customize button click.
const handleCustomizeBtnClick = () => {
openDrawer(DRAWERS.BRANDING_TEMPLATES, { resource: 'CreditNote' });
};

const brandingTemplatesOptions = useCreditNoteFormBrandingTemplatesOptions();

return (
Expand Down Expand Up @@ -202,7 +211,7 @@ export default function CreditNoteFloatingActions() {
/>
</Group>

<Group>
<Group spacing={0}>
{/* ----------- Branding Template Select ----------- */}
<BrandingThemeFormGroup
name={'pdf_template_id'}
Expand All @@ -221,6 +230,26 @@ export default function CreditNoteFloatingActions() {
popoverProps={{ minimal: true }}
/>
</BrandingThemeFormGroup>

{/* ----------- Setting Select ----------- */}
<Popover
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.TOP_RIGHT}
modifiers={{
offset: { offset: '0, 4' },
}}
content={
<Menu>
<MenuItem
text={'Customize Templates'}
onClick={handleCustomizeBtnClick}
/>
</Menu>
}
>
<Button minimal icon={<MoreIcon height={'14px'} width={'14px'} />} />
</Popover>
</Group>
</PageForm.FooterActions>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ import { useHistory } from 'react-router-dom';
import { useFormikContext } from 'formik';
import { useEstimateFormContext } from './EstimateFormProvider';
import { useEstimateFormBrandingTemplatesOptions } from './utils';
import { useDrawerActions } from '@/hooks/state';
import {
BrandingThemeFormGroup,
BrandingThemeSelectButton,
} from '@/containers/BrandingTemplates/BrandingTemplatesSelectFields';
import { PageForm } from '@/components/PageForm';
import { MoreIcon } from '@/icons/More';
import { DRAWERS } from '@/constants/drawers';

/**
* Estimate floating actions bar.
*/
export default function EstimateFloatingActions() {
const history = useHistory();
const { openDrawer } = useDrawerActions();
const { resetForm, submitForm, isSubmitting } = useFormikContext();

// Estimate form context.
Expand Down Expand Up @@ -77,6 +81,11 @@ export default function EstimateFloatingActions() {
resetForm();
};

// Handles the invoice customize button click.
const handleCustomizeBtnClick = () => {
openDrawer(DRAWERS.BRANDING_TEMPLATES, { resource: 'SaleEstimate' });
};

const brandingTemplatesOptions = useEstimateFormBrandingTemplatesOptions();

return (
Expand Down Expand Up @@ -199,7 +208,7 @@ export default function EstimateFloatingActions() {
/>
</Group>

<Group>
<Group spacing={0}>
{/* ----------- Branding Template Select ----------- */}
<BrandingThemeFormGroup
name={'pdf_template_id'}
Expand All @@ -218,6 +227,26 @@ export default function EstimateFloatingActions() {
popoverProps={{ minimal: true }}
/>
</BrandingThemeFormGroup>

{/* ----------- More Select ----------- */}
<Popover
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.TOP_RIGHT}
modifiers={{
offset: { offset: '0, 4' },
}}
content={
<Menu>
<MenuItem
text={'Customize Templates'}
onClick={handleCustomizeBtnClick}
/>
</Menu>
}
>
<Button minimal icon={<MoreIcon height={'14px'} width={'14px'} />} />
</Popover>
</Group>
</PageForm.FooterActions>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ import { useFormikContext } from 'formik';
import { If, Icon, FormattedMessage as T, Group, FSelect } from '@/components';
import { useInvoiceFormContext } from './InvoiceFormProvider';
import { useInvoiceFormBrandingTemplatesOptions } from './utils';
import { useDrawerActions } from '@/hooks/state';
import {
BrandingThemeFormGroup,
BrandingThemeSelectButton,
} from '@/containers/BrandingTemplates/BrandingTemplatesSelectFields';
import { PageForm } from '@/components/PageForm';
import { MoreIcon } from '@/icons/More';
import { DRAWERS } from '@/constants/drawers';

/**
* Invoice floating actions bar.
*/
export default function InvoiceFloatingActions() {
const history = useHistory();
const { openDrawer } = useDrawerActions();

// Formik context.
const { resetForm, submitForm, isSubmitting } = useFormikContext();
Expand Down Expand Up @@ -79,6 +83,11 @@ export default function InvoiceFloatingActions() {
resetForm();
};

// Handles the invoice customize button click.
const handleCustomizeBtnClick = () => {
openDrawer(DRAWERS.BRANDING_TEMPLATES, { resource: 'SaleInvoice' });
};

const brandingTemplatesOptions = useInvoiceFormBrandingTemplatesOptions();

return (
Expand Down Expand Up @@ -200,7 +209,7 @@ export default function InvoiceFloatingActions() {
/>
</Group>

<Group spacing={10}>
<Group spacing={0}>
{/* ----------- Branding Template Select ----------- */}
<BrandingThemeFormGroup
name={'pdf_template_id'}
Expand All @@ -213,12 +222,31 @@ export default function InvoiceFloatingActions() {
name={'pdf_template_id'}
items={brandingTemplatesOptions}
input={({ activeItem, text, label, value }) => (
<BrandingThemeSelectButton text={text || 'Brand Theme'} minimal />
<BrandingThemeSelectButton text={text || 'Brand Theme'} />
)}
filterable={false}
popoverProps={{ minimal: true }}
/>
</BrandingThemeFormGroup>

<Popover
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.TOP_RIGHT}
modifiers={{
offset: { offset: '0, 4' },
}}
content={
<Menu>
<MenuItem
text={'Customize Templates'}
onClick={handleCustomizeBtnClick}
/>
</Menu>
}
>
<Button minimal icon={<MoreIcon height={'14px'} width={'14px'} />} />
</Popover>
</Group>
</PageForm.FooterActions>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ import {
MenuItem,
} from '@blueprintjs/core';
import { useHistory } from 'react-router-dom';
import { FSelect, Group, Icon, FormattedMessage as T } from '@/components';
import { useFormikContext } from 'formik';
import { FSelect, Group, Icon, FormattedMessage as T } from '@/components';
import { useDrawerActions } from '@/hooks/state';
import { usePaymentReceiveFormContext } from './PaymentReceiveFormProvider';
import {
BrandingThemeFormGroup,
BrandingThemeSelectButton,
} from '@/containers/BrandingTemplates/BrandingTemplatesSelectFields';
import { usePaymentReceivedFormBrandingTemplatesOptions } from './utils';
import { PageForm } from '@/components/PageForm';
import { MoreIcon } from '@/icons/More';
import { DRAWERS } from '@/constants/drawers';

/**
* Payment receive floating actions bar.
Expand All @@ -34,6 +37,8 @@ export default function PaymentReceiveFormFloatingActions() {
// History context.
const history = useHistory();

const { openDrawer } = useDrawerActions();

// Handle submit button click.
const handleSubmitBtnClick = (event) => {
setSubmitPayload({ redirect: true });
Expand All @@ -57,6 +62,11 @@ export default function PaymentReceiveFormFloatingActions() {
submitForm();
};

// Handles the invoice customize button click.
const handleCustomizeBtnClick = () => {
openDrawer(DRAWERS.BRANDING_TEMPLATES, { resource: 'PaymentReceive' });
};

const brandingTemplatesOpts =
usePaymentReceivedFormBrandingTemplatesOptions();

Expand Down Expand Up @@ -115,7 +125,7 @@ export default function PaymentReceiveFormFloatingActions() {
/>
</Group>

<Group>
<Group spacing={0}>
{/* ----------- Branding Template Select ----------- */}
<BrandingThemeFormGroup
name={'pdf_template_id'}
Expand All @@ -134,6 +144,26 @@ export default function PaymentReceiveFormFloatingActions() {
popoverProps={{ minimal: true }}
/>
</BrandingThemeFormGroup>

{/* ----------- Setting Select ----------- */}
<Popover
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.TOP_RIGHT}
modifiers={{
offset: { offset: '0, 4' },
}}
content={
<Menu>
<MenuItem
text={'Customize Templates'}
onClick={handleCustomizeBtnClick}
/>
</Menu>
}
>
<Button minimal icon={<MoreIcon height={'14px'} width={'14px'} />} />
</Popover>
</Group>
</PageForm.FooterActions>
);
Expand Down
Loading
Loading