Skip to content

Commit 53b9ec6

Browse files
committed
Refactor /app/pages/common/Modals/PreferencesModal/PaymentInfo/index.tsx to use overmind
1 parent f7a25a3 commit 53b9ec6

File tree

5 files changed

+69
-66
lines changed

5 files changed

+69
-66
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React, { useEffect } from 'react';
2+
import { SubscribeForm } from 'app/components/SubscribeForm';
3+
import { useOvermind } from 'app/overmind';
4+
import { Card } from './Card';
5+
import { Title, Subheading } from '../elements';
6+
import { Container, CustomSubHeading } from './elements';
7+
8+
export const PaymentInfo: React.FunctionComponent = () => {
9+
const {
10+
state: {
11+
preferences: {
12+
paymentDetailError,
13+
paymentDetails: paymentDetailsFromHooks,
14+
isLoadingPaymentDetails,
15+
},
16+
},
17+
actions: {
18+
preferences: { paymentDetailsRequested, paymentDetailsUpdated },
19+
},
20+
} = useOvermind();
21+
useEffect(() => {
22+
paymentDetailsRequested();
23+
}, [paymentDetailsRequested]);
24+
25+
const updatePaymentDetails = ({ token }) => {
26+
paymentDetailsUpdated({ token });
27+
};
28+
29+
const paymentDetails = () => {
30+
const { last4, name, brand } = paymentDetailsFromHooks;
31+
if (paymentDetailError)
32+
return <div>An error occurred: {paymentDetailError}</div>;
33+
34+
return (
35+
<div>
36+
<Subheading>Current card</Subheading>
37+
<Card last4={last4} name={name} brand={brand} />
38+
39+
<CustomSubHeading>Update card info</CustomSubHeading>
40+
<SubscribeForm
41+
buttonName="Update"
42+
loadingText="Updating Card Info..."
43+
name={name}
44+
subscribe={updatePaymentDetails}
45+
/>
46+
</div>
47+
);
48+
};
49+
50+
return (
51+
<Container>
52+
<Title>Payment Info</Title>
53+
{isLoadingPaymentDetails ? (
54+
<div>Loading payment details...</div>
55+
) : (
56+
paymentDetails()
57+
)}
58+
</Container>
59+
);
60+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import styled from 'styled-components';
2+
import { Subheading } from '../elements';
23

34
export const Container = styled.div`
45
font-weight: 400;
56
color: rgba(255, 255, 255, 0.6);
67
`;
8+
9+
export const CustomSubHeading = styled(Subheading)`
10+
margin-top: 2rem;
11+
`;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { PaymentInfo } from './PaymentInfo';
2+
3+
export default PaymentInfo;

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

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

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)