Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/billing/payment-method.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Rendered, useState } from "../app-framework";6import {7Alert,8Button,9ButtonToolbar,10Row,11Col,12} from "@cocalc/frontend/antd-bootstrap";13import { Icon, IconName } from "../components/icon";14import { Gap } from "../components/gap";15import { brand_to_icon_name } from "./data";1617import { Source } from "./types";1819interface Props {20source: Source;21default?: boolean; // required for set_as_default22set_as_default?: Function; // called when this card should be set to default23delete_method?: Function; // called when this card should be deleted24}2526export const PaymentMethod: React.FC<Props> = (props) => {27const [confirm_default, set_confirm_default] = useState<boolean>(false);28const [confirm_delete, set_confirm_delete] = useState<boolean>(false);2930function icon_name(): IconName {31return brand_to_icon_name(32props.source.brand != null ? props.source.brand.toLowerCase() : undefined,33);34}3536function render_confirm_default(): Rendered {37return (38<Alert bsStyle="warning">39<Row>40<Col md={5} mdOffset={2}>41<p>42Are you sure you want to set this payment card to be the default?43</p>44<p>45All future payments will be made with the card that is the default{" "}46<b>at the time of renewal</b>. Changing your default card right47before a subscription renewal will cause the <Gap />48new default to be charged instead of the previous one.49</p>50</Col>51<Col md={5}>52<ButtonToolbar>53<Button54onClick={() => {55set_confirm_default(false);56if (props.set_as_default != null) props.set_as_default();57}}58bsStyle="warning"59>60<Icon name="trash" /> Set to Default61</Button>62<Button onClick={() => set_confirm_default(false)}>Cancel</Button>63</ButtonToolbar>64</Col>65</Row>66</Alert>67);68}6970function render_confirm_delete(): Rendered {71return (72<Alert bsStyle="danger">73<Row>74<Col md={5} mdOffset={2}>75Are you sure you want to delete this payment method?76</Col>77<Col md={5}>78<ButtonToolbar>79<Button80bsStyle="danger"81onClick={() => {82set_confirm_delete(false);83if (props.delete_method != null) props.delete_method();84}}85>86<Icon name="trash" /> Delete Payment Method87</Button>88<Button onClick={() => set_confirm_delete(false)}>Cancel</Button>89</ButtonToolbar>90</Col>91</Row>92</Alert>93);94}9596function render_card(): Rendered {97return (98<Row>99<Col md={2}>100<Icon name={icon_name()} /> {props.source.brand}101</Col>102<Col md={1}>103<em>····</em>104{props.source.last4}105</Col>106<Col md={1}>107{props.source.exp_month}/{props.source.exp_year}108</Col>109<Col md={2}>{props.source.name}</Col>110<Col md={1}>{props.source.address_country}</Col>111<Col md={2}>112{props.source.address_state}113<Gap />114<Gap />115{props.source.address_zip}116</Col>117{props.set_as_default != null || props.delete_method != null118? render_action_buttons()119: undefined}120</Row>121);122}123124function render_action_buttons(): Rendered {125return (126<Col md={3}>127<ButtonToolbar style={{ float: "right" }}>128{props.set_as_default != null ? (129<Button130onClick={() => set_confirm_default(true)}131disabled={props.default}132bsStyle={props.default ? "primary" : "default"}133>134Default{!props.default ? <span>... </span> : undefined}135</Button>136) : undefined}137138{props.delete_method != null ? (139<Button onClick={() => set_confirm_delete(true)}>140<Icon name="trash" /> Delete141</Button>142) : undefined}143</ButtonToolbar>144</Col>145);146}147148return (149<div150style={{151borderBottom: "1px solid #999",152paddingTop: "5px",153paddingBottom: "5px",154}}155>156{render_card()}157{confirm_default ? render_confirm_default() : undefined}158{confirm_delete ? render_confirm_delete() : undefined}159</div>160);161};162163164