2021-07-06 22:28:29 +02:00
|
|
|
// @flow
|
2021-07-17 18:19:44 +02:00
|
|
|
import React from 'react';
|
2021-07-06 22:28:29 +02:00
|
|
|
import { Modal } from 'modal/modal';
|
|
|
|
import Card from 'component/common/card';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
import { Lbryio } from 'lbryinc';
|
2021-08-17 20:28:38 +02:00
|
|
|
import { getStripeEnvironment } from 'util/stripe';
|
|
|
|
let stripeEnvironment = getStripeEnvironment();
|
2021-07-06 22:28:29 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
closeModal: () => void,
|
|
|
|
paymentMethodId: string,
|
2021-08-17 20:28:38 +02:00
|
|
|
setAsConfirmingCard: () => void, // ?
|
2021-07-06 22:28:29 +02:00
|
|
|
};
|
|
|
|
|
2021-08-17 20:28:38 +02:00
|
|
|
export default function ModalRemoveCard(props: Props) {
|
|
|
|
const { closeModal, paymentMethodId } = props;
|
2021-07-06 22:28:29 +02:00
|
|
|
|
2021-07-17 18:19:44 +02:00
|
|
|
function removeCard() {
|
2021-07-06 22:28:29 +02:00
|
|
|
Lbryio.call(
|
|
|
|
'customer',
|
|
|
|
'detach',
|
|
|
|
{
|
|
|
|
environment: stripeEnvironment,
|
2021-07-17 18:19:44 +02:00
|
|
|
payment_method_id: paymentMethodId,
|
2021-07-06 22:28:29 +02:00
|
|
|
},
|
|
|
|
'post'
|
|
|
|
).then((removeCardResponse) => {
|
2021-07-17 18:19:44 +02:00
|
|
|
// TODO: add toast here
|
2021-07-06 22:28:29 +02:00
|
|
|
// closeModal();
|
2021-08-17 20:28:38 +02:00
|
|
|
// Is there a better way to handle this? Why reload?
|
2021-07-17 18:19:44 +02:00
|
|
|
window.location.reload();
|
2021-07-06 22:28:29 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal ariaHideApp={false} isOpen contentLabel={'hello'} type="card" onAborted={closeModal}>
|
|
|
|
<Card
|
2021-08-17 20:28:38 +02:00
|
|
|
title={__('Confirm Remove Card')}
|
2021-07-06 22:28:29 +02:00
|
|
|
actions={
|
|
|
|
<div className="section__actions">
|
|
|
|
<Button
|
|
|
|
className="stripe__confirm-remove-card"
|
|
|
|
button="secondary"
|
|
|
|
icon={ICONS.DELETE}
|
2021-08-17 20:28:38 +02:00
|
|
|
label={__('Remove Card')}
|
2021-07-06 22:28:29 +02:00
|
|
|
onClick={removeCard}
|
|
|
|
/>
|
|
|
|
<Button button="link" label={__('Cancel')} onClick={closeModal} />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|