-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpurchase-flow.stories.svelte
153 lines (143 loc) · 4.26 KB
/
purchase-flow.stories.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<script module>
import {
defineMeta,
setTemplate,
type StoryContext,
type Args,
} from "@storybook/addon-svelte-csf";
import PurchasesInner from "../ui/purchases-ui-inner.svelte";
import { brandingLanguageViewportModes } from "../../.storybook/modes";
import {
brandingInfos,
product,
purchaseFlowError,
subscriptionOption,
subscriptionOptionWithTrial,
} from "./fixtures";
import { buildCheckoutStartResponse } from "./utils/purchase-response-builder";
import { type CheckoutStartResponse } from "../networking/responses/checkout-start-response";
import { toProductInfoStyleVar } from "../ui/theme/utils";
import { PurchaseOperationHelper } from "../helpers/purchase-operation-helper";
const defaultArgs = {
productDetails: product,
purchaseOptionToUse: subscriptionOption,
purchaseOption: subscriptionOption,
lastError: purchaseFlowError,
onContinue: () => {},
};
let paymentInfoCollectionMetadata: any;
let { Story } = defineMeta({
title: "Flows/Purchase",
args: defaultArgs,
parameters: {
chromatic: {
modes: brandingLanguageViewportModes,
delay: 500,
},
},
globals: {
viewport: { value: "mobile", isRotated: false },
},
loaders: [
async () => {
const checkoutStartResponse: CheckoutStartResponse =
await buildCheckoutStartResponse();
paymentInfoCollectionMetadata = { ...checkoutStartResponse };
return { paymentInfoCollectionMetadata };
},
],
});
</script>
<script lang="ts">
setTemplate(template);
</script>
{#snippet template(
args: Args<typeof Story>,
context: StoryContext<typeof Story>,
)}
{#if context.globals.viewport === "embedded"}
{@render embedded(args, context)}
{:else}
{@render Purchases(args, context)}
{/if}
{/snippet}
{#snippet Purchases(
args: Args<typeof Story>,
context: StoryContext<typeof Story>,
)}
{@const brandingInfo = brandingInfos[context.globals.brandingName]}
{@const colorVariables = toProductInfoStyleVar(brandingInfo.appearance)}
<PurchasesInner
isSandbox={args.isSandbox}
currentView={args.currentView}
productDetails={args.productDetails}
purchaseOptionToUse={args.purchaseOptionToUse}
{brandingInfo}
{colorVariables}
handleContinue={() => {}}
closeWithError={() => {}}
lastError={null}
{paymentInfoCollectionMetadata}
purchaseOperationHelper={null as unknown as PurchaseOperationHelper}
isInElement={args.isInElement}
/>
{/snippet}
{#snippet embedded(
args: Args<typeof Story>,
context: StoryContext<typeof Story>,
)}
<div style="width: 100vw; height:100vh; background-color: red;">
<div style="display: flex">
<div
id="embedding-container"
style="width: 500px; height: 600px; position: relative; overflow: hidden; background-color: lightgray;"
>
{@render Purchases({ ...args, isInElement: true }, context)}
</div>
<div style="padding: 20px;">
<h1>Homer's Web page</h1>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam,
quos.
</p>
</div>
</div>
</div>
{/snippet}
<Story name="Email Input" args={{ currentView: "needs-auth-info" }} />
<Story
name="Email Input (with Sandbox Banner)"
args={{ currentView: "needs-auth-info", isSandbox: true }}
/>
<Story
name="Email Input (with Trial Product)"
args={{
currentView: "needs-auth-info",
isSandbox: true,
productDetails: {
...product,
normalPeriodDuration: "P1Y",
},
purchaseOptionToUse: subscriptionOptionWithTrial,
}}
/>
<Story name="Checkout" args={{ currentView: "needs-payment-info" }} />
<Story
name="Checkout (with Trial Product)"
args={{
...defaultArgs,
currentView: "needs-payment-info",
productDetails: {
...product,
subscriptionOptions: {
...product.subscriptionOptions,
[subscriptionOptionWithTrial.id]: subscriptionOptionWithTrial,
},
},
purchaseOptionToUse: subscriptionOptionWithTrial,
defaultPurchaseOption: subscriptionOptionWithTrial,
}}
/>
<Story name="Loading" args={{ currentView: "loading" }} />
<Story name="Payment complete" args={{ currentView: "success" }} />
<Story name="Payment failed" args={{ currentView: "error" }} />