-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
200 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
import React from 'react'; | ||
|
||
import { Section, Wrapper } from 'common/base'; | ||
import Heading from 'common/base/Heading'; | ||
import TabLinkGroup from 'common/TabLinkGroup'; | ||
|
||
import AuthMask from './AuthMask'; | ||
|
||
import styles from './SubscriptionWrapper.module.css'; | ||
|
||
const SubscriptionWrapper = ({ children }) => { | ||
return ( | ||
<AuthMask title="登入以查看我的方案"> | ||
<div className={styles.container}> | ||
<Heading as="h1" style={{ marginBottom: '48px' }}> | ||
const options = [ | ||
{ | ||
label: '我的方案', | ||
to: '/me/subscriptions/current', | ||
}, | ||
{ | ||
label: '方案紀錄', | ||
to: '/me/subscriptions', | ||
}, | ||
]; | ||
|
||
const SubscriptionWrapper = ({ children }) => ( | ||
<Section paddingTop paddingBottom> | ||
<Wrapper size="l"> | ||
<AuthMask title="登入以查看我的方案"> | ||
<Heading as="h1" marginBottom> | ||
我的方案 | ||
</Heading> | ||
<div style={{ display: 'inline-block' }}>{children}</div> | ||
</div> | ||
</AuthMask> | ||
); | ||
}; | ||
<TabLinkGroup className={styles.tabs} options={options} /> | ||
<div> | ||
<div style={{ display: 'inline-block' }}>{children}</div> | ||
</div> | ||
</AuthMask> | ||
</Wrapper> | ||
</Section> | ||
); | ||
|
||
export default SubscriptionWrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,3 @@ | ||
@value above-medium, above-mobile from "common/variables.module.css"; | ||
|
||
.container { | ||
padding: 20px 10px 0 10px; | ||
|
||
@media (min-width: above-mobile) { | ||
padding: 40px 100px 0 100px; | ||
} | ||
|
||
@media (min-width: above-medium) { | ||
padding: 60px 340px 0 340px; | ||
} | ||
.tabs { | ||
margin-bottom: 24px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import cn from 'classnames'; | ||
import { format } from 'date-fns'; | ||
import SubscriptionWrapper from './SubscriptionWrapper'; | ||
import { | ||
getError, | ||
getFetched, | ||
getUnfetched, | ||
isFetched, | ||
isFetching, | ||
toFetching, | ||
} from 'utils/fetchBox'; | ||
import Loader from 'common/Loader'; | ||
import Table from 'common/table/Table'; | ||
import { subscriptionStatus, isFailed } from './subscriptionUtils'; | ||
import styles from './SubscriptionsPage.module.css'; | ||
import { useToken } from 'hooks/auth'; | ||
import apis from '../../apis'; | ||
|
||
const formatCreatedAt = value => format(new Date(value), 'yyyy/MM/dd'); | ||
const formatTitle = ({ subscriptionPlan: { title, description } }) => | ||
`${title} - ${description}`; | ||
const formatDuration = ({ startedAt, expiredAt }) => ( | ||
<span> | ||
{`${format(new Date(startedAt), 'yyyy-MM-dd hh:mm a')} ~`} | ||
<br /> | ||
{format(new Date(expiredAt), 'yyyy-MM-dd hh:mm a')} | ||
</span> | ||
); | ||
const formatAmount = value => value && `$${value}`; | ||
const formatStatus = value => ( | ||
<span className={cn({ [styles.failed]: isFailed(value) })}> | ||
{subscriptionStatus[value]} | ||
</span> | ||
); | ||
|
||
const Subscriptions = () => { | ||
const [mySubscriptions, setMySubscriptions] = useState(getUnfetched()); | ||
const token = useToken(); | ||
|
||
useEffect(() => { | ||
setMySubscriptions(toFetching(mySubscriptions)); | ||
|
||
const fetcher = apis.payment.getMySubscriptions(token); | ||
|
||
fetcher() | ||
.then(subscriptions => { | ||
setMySubscriptions(getFetched(subscriptions)); | ||
}) | ||
.catch(error => { | ||
console.error(error); | ||
setMySubscriptions(getError(error)); | ||
}); | ||
}, []); // eslint-disable-line react-hooks/exhaustive-deps | ||
|
||
if (!mySubscriptions) return null; | ||
|
||
if (isFetching(mySubscriptions)) return <Loader />; | ||
|
||
if (!isFetched(mySubscriptions)) return null; | ||
|
||
const { data } = mySubscriptions; | ||
|
||
return ( | ||
<Table className={styles.subscriptions} data={data} primaryKey="id"> | ||
<Table.Column | ||
className={styles.m} | ||
title="日期" | ||
dataField="createdAt" | ||
dataFormatter={formatCreatedAt} | ||
/> | ||
<Table.Column | ||
className={styles.m} | ||
title="訂單編號" | ||
dataField="paymentRecord.publicId" | ||
/> | ||
<Table.Column className={styles.l} title="項目" dataField={formatTitle} /> | ||
<Table.Column | ||
className={styles.l} | ||
title="有效期間" | ||
dataField={formatDuration} | ||
/> | ||
<Table.Column | ||
className={styles.m} | ||
title="金額" | ||
dataField="paymentRecord.amount" | ||
dataFormatter={formatAmount} | ||
/> | ||
<Table.Column | ||
className={styles.m} | ||
title="狀態" | ||
dataField="status" | ||
dataFormatter={formatStatus} | ||
/> | ||
</Table> | ||
); | ||
}; | ||
|
||
export default () => ( | ||
<SubscriptionWrapper> | ||
<Subscriptions /> | ||
</SubscriptionWrapper> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.subscriptions { | ||
td { | ||
word-wrap: break-word; | ||
} | ||
|
||
.m { | ||
width: 10%; | ||
} | ||
|
||
.l { | ||
width: 20%; | ||
} | ||
} | ||
|
||
.failed { | ||
color: #ed5555; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const subscriptionStatus = { | ||
INIT: '待確認', | ||
OK: '成功', | ||
FAILED: '失敗', | ||
SUSPENDED: '停權', | ||
}; | ||
|
||
export const isFailed = status => status === 'FAILED' || status === 'SUSPENDED'; |
7 changes: 4 additions & 3 deletions
7
...onents/CompanyAndJobTitle/TabLinkGroup.js → src/components/common/TabLinkGroup/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.