@springmicro/cart 0.3.2 → 0.3.5

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.
Files changed (35) hide show
  1. package/.eslintrc.cjs +21 -21
  2. package/README.md +64 -64
  3. package/dist/index.js +9778 -9696
  4. package/dist/index.umd.cjs +66 -92
  5. package/package.json +5 -3
  6. package/src/AddToCartForm.tsx +16 -16
  7. package/src/CartButton.tsx +249 -249
  8. package/src/ProductCard.css +106 -106
  9. package/src/ProductCard.tsx +165 -165
  10. package/src/checkout/{CheckoutList.css → ReviewCartAndCalculateTaxes.css} +93 -93
  11. package/src/checkout/ReviewCartAndCalculateTaxes.tsx +366 -0
  12. package/src/checkout/components/AddCard.tsx +267 -0
  13. package/src/checkout/components/Address.tsx +261 -265
  14. package/src/checkout/components/CartList.tsx +151 -0
  15. package/src/checkout/components/CartProductCard.css +67 -67
  16. package/src/checkout/components/CartProductCard.tsx +90 -80
  17. package/src/checkout/components/Invoice.tsx +145 -0
  18. package/src/checkout/components/ProviderLogos.tsx +93 -93
  19. package/src/checkout/components/StatusBar.tsx +32 -0
  20. package/src/checkout/index.tsx +161 -0
  21. package/src/index.css +5 -5
  22. package/src/index.ts +36 -35
  23. package/src/types.d.ts +56 -56
  24. package/src/utils/api.ts +67 -67
  25. package/src/utils/cartAuthHandler.ts +50 -50
  26. package/src/utils/index.ts +28 -28
  27. package/src/utils/storage.ts +133 -133
  28. package/tsconfig.json +24 -24
  29. package/tsconfig.node.json +11 -11
  30. package/vite.config.ts +25 -25
  31. package/springmicro-cart-0.2.3.tgz +0 -0
  32. package/src/checkout/CheckoutList.tsx +0 -264
  33. package/src/checkout/components/Billing.tsx +0 -353
  34. package/src/checkout/components/Order.tsx +0 -93
  35. package/src/checkout/components/index.tsx +0 -104
@@ -0,0 +1,267 @@
1
+ import { useFormik, FormikProps } from "formik";
2
+ import * as Yup from "yup";
3
+ import React, {
4
+ ChangeEventHandler,
5
+ useEffect,
6
+ PropsWithChildren,
7
+ useState,
8
+ } from "react";
9
+ import {
10
+ AddressCityField,
11
+ AddressOrganizationNameField,
12
+ AddressCountryField,
13
+ AddressPostalCodeField,
14
+ AddressRegionField,
15
+ AddressStreetField,
16
+ AddressEmailField,
17
+ AddressValues,
18
+ } from "./Address";
19
+ import {
20
+ allCountries,
21
+ allCountriesReverse,
22
+ getPostalCodeDefault,
23
+ } from "@springmicro/utils/address";
24
+ import { Box, Button, Container, TextField, Typography } from "@mui/material";
25
+ import Cards from "react-credit-cards-2";
26
+ import { FocusEventHandler } from "react";
27
+ import {
28
+ formatCreditCardNumber,
29
+ formatCVC,
30
+ formatExpirationDate,
31
+ splitMonthYear,
32
+ expiryDateHasNotPassed,
33
+ } from "@springmicro/utils/payment";
34
+
35
+ // moved to index.ts
36
+ // import "react-credit-cards-2/dist/es/styles-compiled.css";
37
+ import { StripeLogoLink } from "./ProviderLogos";
38
+
39
+ export type CCFocus = "number" | "name" | "cvc" | "expiry";
40
+
41
+ export type CreditCardValues = {
42
+ cvc: string;
43
+ expiry: string;
44
+ focus: CCFocus;
45
+ name: string;
46
+ number: string;
47
+ };
48
+
49
+ export type AddCardProps = {
50
+ contact?: {
51
+ organization?: string;
52
+ email: string;
53
+ first_name: string;
54
+ last_name: string;
55
+ };
56
+ stacked?: boolean;
57
+ error?: string;
58
+ address?: boolean;
59
+ onSubmit?: (
60
+ values: CreditCardValues & Partial<AddressValues>
61
+ ) => Promise<any>;
62
+ PriceDetails?: JSX.Element;
63
+ formData?: {
64
+ formik;
65
+ handleInputChange;
66
+ handleInputFocus;
67
+ formDisabled;
68
+ formError;
69
+ };
70
+ };
71
+
72
+ export const AddCard = ({
73
+ contact,
74
+ error,
75
+ stacked = false,
76
+ address = true,
77
+ PriceDetails,
78
+ formData: {
79
+ formik,
80
+ handleInputChange,
81
+ handleInputFocus,
82
+ formDisabled,
83
+ formError,
84
+ },
85
+ }: AddCardProps) => {
86
+ return (
87
+ <Container id="paymentMethodForm">
88
+ <form
89
+ onSubmit={(e) => {
90
+ e.preventDefault();
91
+ formik.handleSubmit(e);
92
+ }}
93
+ >
94
+ <Box
95
+ sx={
96
+ stacked
97
+ ? {}
98
+ : {
99
+ display: "flex",
100
+ flexDirection: { xs: "column", sm: "row" },
101
+ gap: "1em",
102
+ }
103
+ }
104
+ >
105
+ <Cards
106
+ {...(formik.values as CreditCardValues)}
107
+ focused={formik.values.focus || "number"}
108
+ />
109
+
110
+ <div>
111
+ <TextField
112
+ sx={stacked ? { mt: 2 } : {}}
113
+ fullWidth
114
+ type="tel"
115
+ name="number"
116
+ label="Card Number"
117
+ required
118
+ onBlur={formik.handleBlur}
119
+ onChange={handleInputChange}
120
+ onFocus={handleInputFocus}
121
+ variant="outlined"
122
+ value={formik.values.number}
123
+ error={Boolean(formik.touched.number && formik.errors.number)}
124
+ helperText={formik.touched.number && formik.errors.number}
125
+ />
126
+ <TextField
127
+ sx={{ mt: 2 }}
128
+ fullWidth
129
+ type="text"
130
+ name="name"
131
+ label="Name on Card"
132
+ required
133
+ onBlur={formik.handleBlur}
134
+ onChange={handleInputChange}
135
+ onFocus={handleInputFocus}
136
+ variant="outlined"
137
+ value={formik.values.name}
138
+ error={Boolean(formik.touched.name && formik.errors.name)}
139
+ helperText={formik.touched.name && formik.errors.name}
140
+ />
141
+ <TextField
142
+ sx={{ mt: 2, width: "calc(50% - 8px)", mr: 1 }}
143
+ type="tel"
144
+ name="expiry"
145
+ label="Valid Thru"
146
+ placeholder="MM/YY"
147
+ inputProps={{ pattern: "[0-9]{2}/[0-9]{2}" }}
148
+ required
149
+ onBlur={formik.handleBlur}
150
+ onChange={handleInputChange}
151
+ onFocus={handleInputFocus}
152
+ variant="outlined"
153
+ value={formik.values.expiry}
154
+ error={Boolean(formik.touched.expiry && formik.errors.expiry)}
155
+ helperText={
156
+ (formik.touched.expiry && formik.errors.expiry) || "MM/YY"
157
+ }
158
+ />
159
+ <TextField
160
+ sx={{ mt: 2, width: "calc(50% - 8px)", ml: 1 }}
161
+ type="tel"
162
+ name="cvc"
163
+ label="CVC"
164
+ required
165
+ onBlur={formik.handleBlur}
166
+ onChange={handleInputChange}
167
+ onFocus={handleInputFocus}
168
+ variant="outlined"
169
+ value={formik.values.cvc}
170
+ error={Boolean(formik.touched.cvc && formik.errors.cvc)}
171
+ helperText={formik.touched.cvc && formik.errors.cvc}
172
+ />
173
+ </div>
174
+ {/* {formik.errors.submit && (
175
+ <Typography color="error" sx={{ mt: 2 }} variant="body2">
176
+ {formik.errors.submit}
177
+ </Typography>
178
+ )} */}
179
+ </Box>
180
+ <Box
181
+ sx={{ display: "flex", flexDirection: "row", gap: 2, width: "100%" }}
182
+ >
183
+ <Box sx={{ flexGrow: 1 }}>
184
+ {!address ? null : (
185
+ <Box>
186
+ <Typography variant="h6" sx={{ mt: 2, mb: 3 }}>
187
+ Billing Address
188
+ </Typography>
189
+ <AddressCountryField formik={formik} name="country" />
190
+ <AddressEmailField
191
+ formik={formik}
192
+ name="email"
193
+ sx={{ mt: 2 }}
194
+ />
195
+ <AddressOrganizationNameField
196
+ sx={{ mt: 2 }}
197
+ formik={formik}
198
+ name="organization"
199
+ />
200
+ <AddressStreetField
201
+ sx={{ mt: 2 }}
202
+ formik={formik}
203
+ name="line1"
204
+ lineNo="1"
205
+ />
206
+ <AddressStreetField
207
+ sx={{ mt: 2 }}
208
+ formik={formik}
209
+ name="line2"
210
+ lineNo="2"
211
+ required={false}
212
+ />
213
+ <AddressCityField sx={{ mt: 2 }} formik={formik} name="city" />
214
+ <AddressRegionField
215
+ sx={{ mt: 2 }}
216
+ formik={formik}
217
+ name="region"
218
+ />
219
+ <AddressPostalCodeField
220
+ sx={{ mt: 2 }}
221
+ formik={formik}
222
+ name="postal_code"
223
+ />
224
+ </Box>
225
+ )}
226
+ </Box>
227
+ <Box
228
+ sx={{
229
+ mt: "16px",
230
+ display: "flex",
231
+ flexDirection: "column",
232
+ alignItems: "flex-end",
233
+ flexGrow: 1,
234
+ }}
235
+ >
236
+ {PriceDetails}
237
+ </Box>
238
+ </Box>
239
+ {error && (
240
+ <Typography color="error" sx={{ mt: 2 }} variant="body2">
241
+ {error}
242
+ </Typography>
243
+ )}
244
+ {formError && (
245
+ <Typography color="red">
246
+ Could not create order or calculate tax. Please double-check your
247
+ payment information.
248
+ </Typography>
249
+ )}
250
+ <Button
251
+ size="large"
252
+ sx={{ mt: 3 }}
253
+ variant="contained"
254
+ // onClick={formik.handleSubmit}
255
+ type="submit"
256
+ disabled={formDisabled}
257
+ color={formError ? "error" : undefined}
258
+ >
259
+ Calculate Tax
260
+ </Button>
261
+ <Box sx={{ mt: 1 }}>
262
+ <StripeLogoLink />
263
+ </Box>
264
+ </form>
265
+ </Container>
266
+ );
267
+ };