Skip to content

Commit

Permalink
TEC-4141: Refactored so that the PurchaseSummary component receives t…
Browse files Browse the repository at this point in the history
…he property children to display the child component's information.
  • Loading branch information
juninhokaponne committed Mar 26, 2024
1 parent a55ae12 commit 0dc90fc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
12 changes: 11 additions & 1 deletion src/components/PurchaseSummary/PurchaseSummary.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Meta, StoryObj } from '@storybook/react'
import { PurchaseSummary } from './index'
import { PurchaseSummaryProps } from './type'
import { PurchaseSummaryAccordion } from './PurchaseSummaryAccordion'

export default {
title: 'Components/PurchaseSummary',
Expand Down Expand Up @@ -86,6 +87,7 @@ export const WithDiscounts: Story = {
title: '',
productsLabel: 'Valor dos produtos',
deliveryValue: 'Valor da entrega',
discountLabel: 'Total de descontos',
totalItems: 1,
labelItensText: 'item',
productsPrice: 178.6,
Expand All @@ -106,7 +108,15 @@ export const WithDiscounts: Story = {
},
],
},
render: (args) => <PurchaseSummary {...args} />,
render: (args) => (
<PurchaseSummary {...args}>
<PurchaseSummaryAccordion
title={args.discountLabel}
total={args.totalDiscount}
listDiscount={args.discounts}
/>
</PurchaseSummary>
),
}

export const WithoutDiscounts: Story = {
Expand Down
17 changes: 3 additions & 14 deletions src/components/PurchaseSummary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import {
PurchaseSummaryPaymentInstallments,
} from './style'

import { PurchaseSummaryAccordion } from './PurchaseSummaryAccordion/index'

const PurchaseSummary: React.FC<PurchaseSummaryProps> = ({
title,
productsLabel,
Expand All @@ -26,13 +24,10 @@ const PurchaseSummary: React.FC<PurchaseSummaryProps> = ({
labelItensText,
productsPrice,
deliveryCost,
totalDiscount,
totalPrice,
installmentPayment,
discounts,
children,
}) => {
const hasDiscounts = discounts && discounts.length > 0

return (
<PurchaseSummaryContainer>
{title && <PurchaseSummaryTitle>{title}</PurchaseSummaryTitle>}
Expand All @@ -59,14 +54,8 @@ const PurchaseSummary: React.FC<PurchaseSummaryProps> = ({
</PurchaseSummaryItemContainer>
)}

{hasDiscounts && (
<PurchaseSummaryItemContainer>
<PurchaseSummaryAccordion
title="Total de descontos"
total={totalDiscount}
listDiscount={discounts}
/>
</PurchaseSummaryItemContainer>
{children && (
<PurchaseSummaryItemContainer>{children}</PurchaseSummaryItemContainer>
)}

<PurchaseSummaryLineDivider />
Expand Down
2 changes: 2 additions & 0 deletions src/components/PurchaseSummary/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type PurchaseSummaryProps = {
totalPrice: number
installmentPayment?: string
discounts: Array<PurchaseSummaryDiscountItemProps>
children?: React.ReactNode
discountLabel: string
}

type PurchaseSummaryDiscountItemProps = {
Expand Down

0 comments on commit 0dc90fc

Please sign in to comment.