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
import SuccessTransaction from './SuccessTransaction'; | |
import FailTransaction from './FailTransaction'; | |
import PendingTransaction from './PendingTransaction'; | |
class Transaction { | |
constructor(transaction) { | |
this.id = transaction.id; | |
this.transactionStatusDelegate = this.getTransactionStatusDelegate(transaction); | |
} | |
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
import { useQuery } from 'react-query'; | |
import apis from '../apis'; | |
const useUser = () => useQuery( | |
['user'], | |
async () => { | |
const createGuestUser = () => ({ | |
name: '遊客', | |
submitComment: () => { /* 導到登入頁面 */ }, | |
}); |
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
import { useQuery } from 'react-query'; | |
import apis from '../apis'; | |
const useUser = () => useQuery( | |
['user'], | |
async () => { | |
const { data: user } = await apis.getUser(); | |
return user; | |
} | |
); |
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
import SuccessTransaction from './Transaction/SuccessTransaction'; | |
import FailTransaction from './Transaction/FailTransaction'; | |
import PendingTransaction from './Transaction/PendingTransaction'; | |
const getTransactionInfo = (transaction) => { | |
switch (transaction.status) { | |
case 'SUCCESS': | |
return new SuccessTransaction(transaction); | |
case 'FAIL': | |
return new FailTransaction(transaction); |
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
import Transaction from './Transaction'; | |
class FailTransaction extends Transaction { | |
constructor(transaction) { | |
super(transaction); | |
this.statusString = '失敗'; | |
this.isNonRefundable = true; | |
} | |
} |
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
const getTransactionInfo = () => { | |
switch (transaction.status) { | |
case 'SUCCESS': | |
return { | |
statusString: '成功', | |
isNonRefundable: false, | |
}; | |
case 'FAIL': | |
return { | |
statusString: '失敗', |
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
const TransactionInfo = (transaction) => { | |
const getTransactionInfo = () => { | |
if (transaction.status === 'SUCCESS') { | |
return { | |
statusString: '成功', | |
isNonRefundable: false, | |
}; | |
} | |
return { | |
statusString: '失敗', |
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
const TransactionInfo = (transaction) => ( | |
<div> | |
<label>交易狀態:</label> | |
<span>{ transaction.status === 'SUCCESS' ? '成功' : '失敗' }</span> | |
<button disabled={transaction.status !== 'SUCCESS'}> | |
退款 | |
</button> | |
</div> | |
); |