@thecb/components 5.9.3 → 5.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "5.9.3",
3
+ "version": "5.10.2",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -61,13 +61,15 @@
61
61
  "rollup-plugin-node-resolve": "^5.1.0",
62
62
  "rollup-plugin-visualizer": "^4.0.4",
63
63
  "storybook": "^6.4.22",
64
+ "styled-components": "^5.3.5",
64
65
  "styled-theming": "^2.2.0"
65
66
  },
66
67
  "peerDependencies": {
67
68
  "react": "^16.13.1",
68
69
  "react-dom": "^16.13.1",
69
70
  "react-router-dom": "^6.3.0",
70
- "styled-theming": "^2.2.0"
71
+ "styled-theming": "^2.2.0",
72
+ "styled-components": "^5.1.1"
71
73
  },
72
74
  "husky": {
73
75
  "hooks": {
@@ -83,7 +85,6 @@
83
85
  "ramda": "^0.27.0",
84
86
  "react-aria-modal": "^4.0.0",
85
87
  "react-pose": "^4.0.10",
86
- "redux-freeform": "^5.5.0",
87
- "styled-components": "^5.1.1"
88
+ "redux-freeform": "^5.5.0"
88
89
  }
89
90
  }
@@ -10,7 +10,14 @@ import LabeledAmount from "../../atoms/labeled-amount";
10
10
  import LineItem from "../../atoms/line-item";
11
11
  import Title from "../../atoms/title";
12
12
  import SolidDivider from "../../atoms/solid-divider";
13
- import { FONT_WEIGHT_BOLD } from "../../../constants/style_constants";
13
+ import {
14
+ FONT_WEIGHT_BOLD,
15
+ FONT_WEIGHT_REGULAR
16
+ } from "../../../constants/style_constants";
17
+ import { ATHENS_GREY } from "../../../constants/colors";
18
+ import ButtonWithAction from "../../atoms/button-with-action";
19
+ import Text from "../../atoms/text";
20
+ import { noop } from "../../../util/general";
14
21
 
15
22
  const PaymentDetailsContent = ({
16
23
  lineItemElems,
@@ -18,11 +25,49 @@ const PaymentDetailsContent = ({
18
25
  subtotal,
19
26
  total,
20
27
  variant,
21
- themeValues
28
+ themeValues,
29
+ hasVoidablePaymentsSection,
30
+ voidableTransactionDetails,
31
+ voidableAmountPaid,
32
+ partialVoidAction
22
33
  }) => (
23
34
  <Stack childGap="16px">
24
35
  {lineItemElems}
25
- <SolidDivider />
36
+ {hasVoidablePaymentsSection && (
37
+ <Box background={ATHENS_GREY}>
38
+ <Text variant="p" color={themeValues.text} weight="400">
39
+ Paid
40
+ </Text>
41
+ {voidableTransactionDetails.map(t => (
42
+ <Cluster key={t.id} justify="space-between" align="center">
43
+ <Cluster padding="0" align="center">
44
+ <Box padding="0">{t.voidText}</Box>
45
+ <ButtonWithAction
46
+ variant="ghost"
47
+ action={() => partialVoidAction(t)}
48
+ text="Void"
49
+ extraStyles={"min-width: 75px; margin: 0px;"}
50
+ textExtraStyles={`font-weight: ${FONT_WEIGHT_REGULAR}; font-size: 16px;`}
51
+ />
52
+ </Cluster>
53
+ <Box padding="0" key={t.id}>
54
+ {displayCurrency(t.amount_given)}
55
+ </Box>
56
+ </Cluster>
57
+ ))}
58
+ <Box padding="8px 0px 16px 0px">
59
+ <SolidDivider />
60
+ </Box>
61
+ <LabeledAmount
62
+ fontWeight={FONT_WEIGHT_REGULAR}
63
+ label="Amount paid"
64
+ amount={displayCurrency(voidableAmountPaid)}
65
+ />
66
+ </Box>
67
+ )}
68
+ {!hasVoidablePaymentsSection && !!lineItemElems.length && (
69
+ <SolidDivider /> // avoids duplicate dividers -> case of voidable payment section, that acts as divider
70
+ )}
26
71
  <Box padding="0.5rem 0">
27
72
  <LabeledAmount
28
73
  variant={themeValues.labeledAmountSubtotal}
@@ -35,7 +80,7 @@ const PaymentDetailsContent = ({
35
80
  <LabeledAmount
36
81
  as="p"
37
82
  variant={themeValues.labeledAmountTotal}
38
- label="Total"
83
+ label={hasVoidablePaymentsSection ? "Remaining amount due" : "Total"}
39
84
  amount={displayCurrency(total)}
40
85
  extraStyles={variant === "small" && `font-weight: ${FONT_WEIGHT_BOLD};`}
41
86
  />
@@ -85,7 +130,13 @@ const PaymentDetails = ({
85
130
  collapsibleOnMobile = true,
86
131
  isMobile,
87
132
  supportsTouch,
88
- themeValues
133
+ themeValues,
134
+ // partial void section (optional)
135
+ hasVoidablePaymentsSection = false,
136
+ voidableTransactionDetails = [],
137
+ partialVoidAction = noop,
138
+ voidableAmountPaid = 0
139
+ // end partial void section
89
140
  }) => {
90
141
  const [isOpen, setIsOpen] = useState(initiallyOpen);
91
142
  const fees = _fees
@@ -118,12 +169,34 @@ const PaymentDetails = ({
118
169
  <SolidDivider />
119
170
  <Box padding="8px" />
120
171
  <PaymentDetailsContent
121
- {...{ lineItemElems, feeElems, subtotal, total, themeValues, variant }}
172
+ {...{
173
+ lineItemElems,
174
+ feeElems,
175
+ subtotal,
176
+ total,
177
+ themeValues,
178
+ variant,
179
+ hasVoidablePaymentsSection,
180
+ voidableTransactionDetails,
181
+ voidableAmountPaid,
182
+ partialVoidAction
183
+ }}
122
184
  />
123
185
  </Stack>
124
186
  ) : (
125
187
  <PaymentDetailsContent
126
- {...{ lineItemElems, feeElems, subtotal, total, themeValues, variant }}
188
+ {...{
189
+ lineItemElems,
190
+ feeElems,
191
+ subtotal,
192
+ total,
193
+ themeValues,
194
+ variant,
195
+ hasVoidablePaymentsSection,
196
+ voidableTransactionDetails,
197
+ voidableAmountPaid,
198
+ partialVoidAction
199
+ }}
127
200
  />
128
201
  );
129
202
  const title = hideTitle ? (
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { text, boolean } from "@storybook/addon-knobs";
2
+ import { text, boolean, number } from "@storybook/addon-knobs";
3
3
  import PaymentDetails from "./PaymentDetails";
4
4
  import page from "../../../../.storybook/page";
5
5
 
@@ -52,18 +52,108 @@ const payment = {
52
52
  total: 79033
53
53
  };
54
54
 
55
+ const voidableTransactionDetails = [
56
+ {
57
+ status: "successful",
58
+ id: 3,
59
+ warnings: [],
60
+ payment_type: "Card Payment",
61
+ amount_given: 100,
62
+ amount_processed: 100,
63
+ change_due: 0,
64
+ service_fee: 0,
65
+ credit_card: {
66
+ last_four: "0043"
67
+ },
68
+ bank_account: {
69
+ account_number_last_four: null
70
+ },
71
+ voidText: "Card ending in 0043"
72
+ },
73
+ {
74
+ status: "successful",
75
+ id: 5,
76
+ warnings: [],
77
+ payment_type: "Card Payment",
78
+ amount_given: 100,
79
+ amount_processed: 100,
80
+ change_due: 0,
81
+ service_fee: 0,
82
+ credit_card: {
83
+ last_four: "0043"
84
+ },
85
+ bank_account: {
86
+ account_number_last_four: null
87
+ },
88
+ voidText: "Card ending in 0043"
89
+ },
90
+ {
91
+ status: "successful",
92
+ id: 6,
93
+ warnings: [],
94
+ payment_type: "Check Payment",
95
+ amount_given: 200,
96
+ amount_processed: 200,
97
+ change_due: 0,
98
+ service_fee: 0,
99
+ credit_card: {
100
+ last_four: null
101
+ },
102
+ bank_account: {
103
+ account_number_last_four: "123"
104
+ },
105
+ voidText: "Account ending in 123"
106
+ }
107
+ ];
108
+
109
+ const lineItems2 = [
110
+ {
111
+ amount: 500,
112
+ description: "Point of Sale Manual Entry - CLERK",
113
+ quantity: 1,
114
+ subDescription: "Test description"
115
+ }
116
+ ];
117
+
55
118
  export const paymentDetails = () => (
56
119
  <PaymentDetails
57
- subtotal={text("subtotal", payment.subtotal, "props")}
120
+ subtotal={text("subtotal", String(payment.subtotal), "props")}
58
121
  lineItems={payment.lineItems}
59
122
  fees={payment.fees}
60
- total={text("total", payment.total, "props")}
123
+ total={text("total", String(payment.total), "props")}
124
+ collapsibleOnMobile={boolean("collapsibleOnMobile", false, "props")}
125
+ initiallyOpen={boolean("initiallyOpen", true, "props")}
126
+ hideTitle={boolean("hideTitle", false, "props")}
127
+ />
128
+ );
129
+
130
+ export const paymentDetailsWithPartialVoids = () => (
131
+ <PaymentDetails
132
+ subtotal={100}
133
+ lineItems={lineItems2}
134
+ fees={[]}
135
+ total={100}
61
136
  collapsibleOnMobile={boolean("collapsibleOnMobile", false, "props")}
62
137
  initiallyOpen={boolean("initiallyOpen", true, "props")}
63
138
  hideTitle={boolean("hideTitle", false, "props")}
139
+ // partial voids section (optional)
140
+ hasVoidablePaymentsSection={boolean(
141
+ "hasVoidablePaymentsSection",
142
+ true,
143
+ "props"
144
+ )}
145
+ voidableTransactionDetails={voidableTransactionDetails}
146
+ partialVoidAction={transaction => {
147
+ console.log(`Your function to void payment id: ${transaction.id}`);
148
+ }}
149
+ voidableAmountPaid={number("voidableAmountPaid", 400)}
150
+ // end partial void section
64
151
  />
65
152
  );
66
153
 
154
+ paymentDetailsWithPartialVoids.storyName =
155
+ "Payment Details (with partial voids)";
156
+
67
157
  const story = page({
68
158
  title: "Components|Molecules/PaymentDetails",
69
159
  Component: PaymentDetails