-
-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding payment providers component to show all payment types
- Loading branch information
Showing
4 changed files
with
192 additions
and
1 deletion.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
frontend/src/components/design-library/atoms/payment-provider/payment-provider.stories.tsx
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,55 @@ | ||
import React from 'react'; | ||
|
||
import PaymentProvider from './payment-provider'; | ||
|
||
// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export | ||
export default { | ||
title: 'Design Library/Atoms/Payment Provider', | ||
component: PaymentProvider, | ||
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes | ||
//argTypes: { | ||
// tags: { control: '' }, | ||
//}, | ||
}; | ||
|
||
// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args | ||
const Template = (args) => <PaymentProvider {...args} />; | ||
|
||
export const Primary = Template.bind({}); | ||
// More on args: https://storybook.js.org/docs/react/writing-stories/args | ||
Primary.args = { | ||
provider: 'stripe', | ||
sourceType: 'card', | ||
}; | ||
|
||
export const Card = Template.bind({}); | ||
Card.args = { | ||
provider: 'stripe', | ||
sourceType: 'card', | ||
}; | ||
|
||
export const Invoice = Template.bind({}); | ||
Invoice.args = { | ||
provider: 'stripe', | ||
sourceType: 'invoice-item', | ||
}; | ||
|
||
export const Paypal = Template.bind({}); | ||
Paypal.args = { | ||
provider: 'paypal', | ||
sourceType: 'unknown', | ||
}; | ||
|
||
export const Wallet = Template.bind({}); | ||
Wallet.args = { | ||
provider: 'wallet', | ||
sourceType: 'unknown', | ||
}; | ||
|
||
export const Unknown = Template.bind({}); | ||
Unknown.args = { | ||
provider: 'unknown', | ||
sourceType: 'unknown', | ||
}; | ||
|
||
|
122 changes: 122 additions & 0 deletions
122
frontend/src/components/design-library/atoms/payment-provider/payment-provider.tsx
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,122 @@ | ||
import React from 'react'; | ||
import { createStyles, Theme, makeStyles } from '@material-ui/core/styles'; | ||
import { orange, green, blue } from '@material-ui/core/colors'; | ||
import { | ||
CreditCard as CreditCardIcon, | ||
Receipt as InvoiceIcon, | ||
AccountBalanceWallet as WalletIcon, | ||
MoneyOff as UnknownPaymentIcon | ||
} from '@material-ui/icons'; | ||
import { Chip } from '@material-ui/core'; | ||
import { paymentProviders, paymentSources } from '../../../../consts' | ||
|
||
const logoPaypal = require('../../../../images/paypal-icon.png').default; | ||
|
||
const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
card: { | ||
backgroundColor: green[400], | ||
color: theme.palette.common.white, | ||
'& .MuiChip-icon': { | ||
color: theme.palette.common.white, | ||
}, | ||
}, | ||
invoice: { | ||
backgroundColor: orange[600], | ||
color: theme.palette.common.white, | ||
'& .MuiChip-icon': { | ||
color: theme.palette.common.white, | ||
}, | ||
}, | ||
paypal: { | ||
backgroundColor: blue[300], | ||
color: theme.palette.common.white | ||
}, | ||
wallet: { | ||
backgroundColor: theme.palette.grey[500], | ||
color: theme.palette.common.white, | ||
'& .MuiChip-icon': { | ||
color: theme.palette.common.white, | ||
}, | ||
}, | ||
unknown: { | ||
backgroundColor: theme.palette.grey[400], | ||
color: theme.palette.common.white, | ||
'& .MuiChip-icon': { | ||
color: theme.palette.common.white, | ||
}, | ||
} | ||
}), | ||
); | ||
|
||
type statusProps = { | ||
provider: string; | ||
sourceType: string; | ||
} | ||
|
||
type GetPaymentTypesProps = { | ||
label?: string, | ||
color?: 'card' | 'invoice' | 'paypal' | 'wallet' | 'unknown', | ||
icon?: JSX.Element | ||
} | ||
type GetPaymentType = (currentPaymentProvider:string, currentPaymentSource:string) => GetPaymentTypesProps | ||
|
||
export default function PaymentProvider({ provider, sourceType }:statusProps) { | ||
const classes = useStyles(); | ||
|
||
const getStatus:GetPaymentType = (currentPaymentProvider:string, currentPaymentSource:string) => { | ||
let choosenPayment:GetPaymentTypesProps = {}; | ||
switch (currentPaymentProvider) { | ||
case paymentProviders.stripe: | ||
if(currentPaymentSource === paymentSources.invoice) { | ||
choosenPayment = { | ||
label: 'Invoice', | ||
color: 'invoice', | ||
icon: <InvoiceIcon /> | ||
}; | ||
} else | ||
if(currentPaymentSource === paymentSources.card) { | ||
choosenPayment = { | ||
label: 'Card', | ||
color: 'card', | ||
icon: <CreditCardIcon /> | ||
}; | ||
} else { | ||
choosenPayment = { | ||
label: 'Card', | ||
color: 'card', | ||
icon: <CreditCardIcon /> | ||
}; | ||
} | ||
break; | ||
case paymentProviders.paypal: | ||
choosenPayment = { | ||
label: 'Paypal', | ||
color: 'paypal', | ||
icon: <img src={logoPaypal} width={24} alt="Paypal" /> | ||
}; | ||
break; | ||
case paymentProviders.wallet: | ||
choosenPayment = { | ||
label: 'Wallet', | ||
color: 'wallet', | ||
icon: <WalletIcon /> | ||
}; | ||
break; | ||
default: | ||
choosenPayment = { | ||
label: 'Unknown', | ||
color: 'unknown', | ||
icon: <UnknownPaymentIcon /> | ||
}; | ||
break; | ||
} | ||
return choosenPayment; | ||
} | ||
|
||
const currentPaymentType = getStatus(provider, sourceType); | ||
|
||
return ( | ||
<Chip size="small" label={currentPaymentType.label} className={classes[currentPaymentType.color]} icon={currentPaymentType.icon} /> | ||
); | ||
} |
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