Skip to content

Commit f1c9941

Browse files
committed
Merge branch 'overmind/PaymentInfo' of https://github.com/MichaelDeBoey/codesandbox-client into MichaelDeBoey-overmind/PaymentInfo
2 parents 05153c8 + 12cb0c5 commit f1c9941

File tree

5 files changed

+34
-35
lines changed

5 files changed

+34
-35
lines changed

packages/app/src/app/overmind/namespaces/preferences/actions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ export const paymentDetailsRequested: AsyncAction = async ({
8686
state.preferences.isLoadingPaymentDetails = false;
8787
};
8888

89-
export const paymentDetailsUpdated: AsyncAction<{ token: string }> = async (
90-
{ state, effects },
91-
{ token }
89+
export const paymentDetailsUpdated: AsyncAction<string> = async (
90+
{ effects, state },
91+
token
9292
) => {
9393
state.preferences.isLoadingPaymentDetails = true;
9494
state.preferences.paymentDetails = await effects.api.updatePaymentDetails(
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import styled from 'styled-components';
2-
import { Subheading } from '../elements';
32

43
export const Container = styled.div`
54
font-weight: 400;
65
color: rgba(255, 255, 255, 0.6);
76
`;
8-
9-
export const CustomSubHeading = styled(Subheading)`
10-
margin-top: 2rem;
11-
`;

packages/app/src/app/pages/common/Modals/PreferencesModal/PaymentInfo/index.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/app/src/app/pages/common/Modals/PreferencesModal/PaymentInfo/PaymentInfo.tsx renamed to packages/app/src/app/pages/common/Modals/PreferencesModal/PaymentInfo/index.tsx

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,56 @@
1-
import React, { useEffect } from 'react';
1+
import React, { ComponentProps, FunctionComponent, useEffect } from 'react';
2+
23
import { SubscribeForm } from 'app/components/SubscribeForm';
34
import { useOvermind } from 'app/overmind';
4-
import { Card } from './Card';
5+
56
import { Title, Subheading } from '../elements';
6-
import { Container, CustomSubHeading } from './elements';
77

8-
export const PaymentInfo: React.FunctionComponent = () => {
8+
import { Card } from './Card';
9+
import { Container } from './elements';
10+
11+
export const PaymentInfo: FunctionComponent = () => {
912
const {
13+
actions: {
14+
preferences: { paymentDetailsRequested, paymentDetailsUpdated },
15+
},
1016
state: {
1117
preferences: {
12-
paymentDetailError,
13-
paymentDetails: paymentDetailsFromHooks,
1418
isLoadingPaymentDetails,
19+
paymentDetailError,
20+
paymentDetails,
1521
},
1622
},
17-
actions: {
18-
preferences: { paymentDetailsRequested, paymentDetailsUpdated },
19-
},
2023
} = useOvermind();
24+
2125
useEffect(() => {
2226
paymentDetailsRequested();
2327
}, [paymentDetailsRequested]);
2428

25-
const updatePaymentDetails = ({ token }) => {
26-
paymentDetailsUpdated({ token });
27-
};
29+
const updatePaymentDetails: ComponentProps<
30+
typeof SubscribeForm
31+
>['subscribe'] = ({ token }) => paymentDetailsUpdated(token);
2832

29-
const paymentDetails = () => {
30-
const { last4, name, brand } = paymentDetailsFromHooks;
31-
if (paymentDetailError)
33+
const Body = () => {
34+
if (isLoadingPaymentDetails) {
35+
return <div>Loading payment details...</div>;
36+
}
37+
38+
if (paymentDetailError) {
3239
return <div>An error occurred: {paymentDetailError}</div>;
40+
}
3341

3442
return (
3543
<div>
3644
<Subheading>Current card</Subheading>
37-
<Card last4={last4} name={name} brand={brand} />
3845

39-
<CustomSubHeading>Update card info</CustomSubHeading>
46+
<Card brand={paymentDetails.brand} last4={paymentDetails.last4} name={paymentDetails.name} />
47+
48+
<Subheading style={{ marginTop: '2rem' }}>Update card info</Subheading>
49+
4050
<SubscribeForm
4151
buttonName="Update"
4252
loadingText="Updating Card Info..."
43-
name={name}
53+
name={paymentDetails.name}
4454
subscribe={updatePaymentDetails}
4555
/>
4656
</div>
@@ -50,11 +60,8 @@ export const PaymentInfo: React.FunctionComponent = () => {
5060
return (
5161
<Container>
5262
<Title>Payment Info</Title>
53-
{isLoadingPaymentDetails ? (
54-
<div>Loading payment details...</div>
55-
) : (
56-
paymentDetails()
57-
)}
63+
64+
<Body />
5865
</Container>
5966
);
6067
};

packages/app/src/app/pages/common/Modals/PreferencesModal/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { Appearance } from './Appearance';
1717
import { EditorSettings } from './EditorPageSettings/EditorSettings';
1818
import { PreviewSettings } from './EditorPageSettings/PreviewSettings';
1919
import { CodeFormatting } from './CodeFormatting';
20-
import PaymentInfo from './PaymentInfo';
20+
import { PaymentInfo } from './PaymentInfo';
2121
import { Integrations } from './Integrations';
2222
import { Badges } from './Badges';
2323
import { Experiments } from './Experiments';

0 commit comments

Comments
 (0)