diff --git a/app/javascript/bundles/User/components/SubscriptionCancel.jsx b/app/javascript/bundles/User/components/SubscriptionCancel.jsx new file mode 100644 index 00000000..c326e486 --- /dev/null +++ b/app/javascript/bundles/User/components/SubscriptionCancel.jsx @@ -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 ( +
+ + + + Do you want to terminate your current subscription? + + + + Terminating your subscription will stop your current plan and the + benefits you receive from it. + + + + + + + +
+ ) +} + +export const SubscriptionCancel = props => diff --git a/app/javascript/bundles/User/components/UserShow.jsx b/app/javascript/bundles/User/components/UserShow.jsx index 75658476..95eb9a1e 100644 --- a/app/javascript/bundles/User/components/UserShow.jsx +++ b/app/javascript/bundles/User/components/UserShow.jsx @@ -16,24 +16,25 @@ function UserShowView ({ user, subscription, streak }) { const classes = useStyles() return ( - -

Contact Data

-

- Name: -

-

{user.name}

- -

- Email: -

-

{user.email}

- - {subscription && streak && ( + <> + {subscription && subscription.active && streak && (

You have been subscribed for {streak}

)} -
+ +

Contact Data

+

+ Name: +

+

{user.name}

+ +

+ Email: +

+

{user.email}

+
+ ) } diff --git a/app/javascript/packs/user-bundle.js b/app/javascript/packs/user-bundle.js index 84c70448..3c9708d8 100644 --- a/app/javascript/packs/user-bundle.js +++ b/app/javascript/packs/user-bundle.js @@ -2,8 +2,10 @@ import ReactOnRails from 'react-on-rails' import { UserShow } from '../bundles/User/components/UserShow' import { DonationsHistory } from '../bundles/User/components/DonationsHistory' +import { SubscriptionCancel } from '../bundles/User/components/SubscriptionCancel' ReactOnRails.register({ UserShow, - DonationsHistory + DonationsHistory, + SubscriptionCancel }) diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 4d3c934a..b27e7193 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -3,4 +3,5 @@ <%= react_component("UserShow", props: {user: @user, streak: @user.current_streak, subscription: @user.subscription}) %> <%= react_component("DonationsHistory", props: {activePlan: @user.subscription&.plan, donations: @user.donations}) %> + <%= react_component("SubscriptionCancel", props: {user: @user, subscription: @user.subscription}) %>