-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add subscription cancel dialog
- Loading branch information
Showing
4 changed files
with
91 additions
and
15 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
app/javascript/bundles/User/components/SubscriptionCancel.jsx
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,72 @@ | ||
import React, { useState } from 'react' | ||
import Button from '@material-ui/core/Button' | ||
import Dialog from '@material-ui/core/Dialog' | ||
import DialogActions from '@material-ui/core/DialogActions' | ||
import DialogContent from '@material-ui/core/DialogContent' | ||
import DialogContentText from '@material-ui/core/DialogContentText' | ||
import DialogTitle from '@material-ui/core/DialogTitle' | ||
|
||
const SUBSCRIPTION_CANCEL_URL = userID => `/users/${userID}/subscription` | ||
|
||
function SubscriptionCancelView ({ user, subscription }) { | ||
const [open, setOpen] = useState(false) | ||
|
||
const handleClickOpen = () => { | ||
setOpen(true) | ||
} | ||
|
||
const handleClose = () => { | ||
setOpen(false) | ||
} | ||
|
||
const handleSubscriptionCancellation = async () => { | ||
await fetch(SUBSCRIPTION_CANCEL_URL(user.id), { | ||
method: 'delete' | ||
}) | ||
|
||
handleClose() | ||
} | ||
|
||
if (!subscription.active) { | ||
return null | ||
} | ||
|
||
return ( | ||
<div> | ||
<Button color='secondary' onClick={handleClickOpen}> | ||
Cancel Subscription | ||
</Button> | ||
<Dialog | ||
open={open} | ||
onClose={handleClose} | ||
id='cancel-subscription-dialog' | ||
aria-labelledby='cancel-subscription-title' | ||
aria-describedby='cancel-subscription-description' | ||
> | ||
<DialogTitle id='cancel-subscription-title'> | ||
Do you want to terminate your current subscription? | ||
</DialogTitle> | ||
<DialogContent> | ||
<DialogContentText id='cancel-subscription-description'> | ||
Terminating your subscription will stop your current plan and the | ||
benefits you receive from it. | ||
</DialogContentText> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={handleClose} color='primary'> | ||
Close | ||
</Button> | ||
<Button | ||
onClick={handleSubscriptionCancellation} | ||
color='primary' | ||
autoFocus | ||
> | ||
Cancel Subscription | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</div> | ||
) | ||
} | ||
|
||
export const SubscriptionCancel = props => <SubscriptionCancelView {...props} /> |
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