Skip to content

Commit

Permalink
Feature: refine subscription management UI/UX (#7557)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaHungDinh authored Oct 7, 2024
1 parent f75f378 commit 50f58cd
Show file tree
Hide file tree
Showing 21 changed files with 479 additions and 325 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
import cx from 'classnames';

import './style.scss';

const Button = ({icon, children, onClick, href, type, variant, ...rest}) => {
type ButtonProps = {
classnames?: string;
icon?: any;
children: React.ReactNode;
onClick?: () => void;
href?: string;
type?: 'button' | 'submit' | 'reset';
variant?: boolean;
disabled?: boolean;
};

const Button = ({icon, children, onClick, href, type, variant,classnames, ...rest}: ButtonProps) => {
const handleHrefClick = (e) => {
e.preventDefault();
window.parent.location = href;
Expand All @@ -23,14 +35,15 @@ const Button = ({icon, children, onClick, href, type, variant, ...rest}) => {
}
return (
<button
className={cx('give-donor-dashboard-button', 'give-donor-dashboard-button--primary', {
'give-donor-dashboard-button--variant': variant,
className={cx('give-donor-dashboard-button', classnames, {
['give-donor-dashboard-button--primary']: !variant,
['give-donor-dashboard-button--variant']: variant,
})}
onClick={onClick ? () => onClick() : null}
type={type}
{...rest}
>
{children}
<span>{children}</span>
{icon && <FontAwesomeIcon icon={icon} />}
</button>
);
Expand Down
48 changes: 37 additions & 11 deletions src/DonorDashboards/resources/js/app/components/button/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
padding: 12px 20px;
font-size: 16px;
font-weight: 600;
border: 1px solid #0073aa;
border: 1px solid var(--give-donor-dashboard-accent-color);
border-radius: 3px;
display: inline-flex;
width: fit-content;
align-items: center;
box-shadow: 0 0 0 0 #7ec980, 0 0 0 0 #4fa651;
transition: box-shadow 0.1s ease, background-color ease-in 0.3s;
Expand All @@ -28,28 +29,53 @@
}

&.give-donor-dashboard-button--primary {
flex: 1;
max-width: 240px;
border: 1px solid #0073aa;
color: #fff !important;
background: #0073aa;
position: relative;
background: none;
box-shadow: none;
justify-content: center;
overflow: hidden;

&:before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: var(--give-donor-dashboard-accent-color);
z-index: 0;
transition: filter 0.3s ease;
}

&:hover:before {
filter: brightness(90%); // Darkens the background on hover
}

&.disabled:before {
display: none;
}

span {
position: relative;
z-index: 1;
}
}

&.give-donor-dashboard-button--variant {
flex: 1;
width: 240px;
color: #0073aa !important;
color: var(--give-donor-dashboard-accent-color) !important;
background: var(--givewp-shades-white);
box-shadow: none;
border: 1px solid #0073aa;
border: 1px solid var(--give-donor-dashboard-accent-color);
margin: 0;
justify-content: center;

&:hover {
background: #0073aa;
color: #fff !important;
filter: brightness(90%);
}

span {
color: inherit;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const SelectControl = ({value, options, isLoading, label = null, onChange = null

const selectedOptionValue = options !== null ? options.filter((option) => option.value === value) : null;
const selectStyles = {
menu: (provided) => ({
...provided,
zIndex: '9999',
}),
control: (provided) => ({
...provided,
fontSize: '14px',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* stylelint-disable function-url-quotes, selector-class-pattern */
.give-donor-dashboard-select-control {
display: flex;
flex-direction: column;
margin-top: 10px;

.give-donor-dashboard-select-control__label {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {useState} from 'react';
import {__} from '@wordpress/i18n';
import Button from '../button';
import {cancelSubscriptionWithAPI} from './utils';

import ModalDialog from '@givewp/components/AdminUI/ModalDialog';
import DashboardLoadingSpinner from '../dashboard-loading-spinner';
import './style.scss';

type SubscriptionCancelProps = {
isOpen: boolean;
toggleModal: () => void;
id: number;
};

const SubscriptionCancelModal = ({isOpen, toggleModal, id}: SubscriptionCancelProps) => {
const [loading, setLoading] = useState<boolean>(false);

const handleCancel = async () => {
setLoading(true);
await cancelSubscriptionWithAPI(id);
setLoading(false);
toggleModal();
};

return (
<ModalDialog
wrapperClassName={'give-donor-dashboard-cancel-modal'}
icon={
<svg width="20" height="20" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M11 0.5C13.7848 0.5 16.4555 1.60625 18.4246 3.57538C20.3938 5.54451 21.5 8.21523 21.5 11C21.5 13.7848 20.3938 16.4555 18.4246 18.4246C16.4555 20.3938 13.7848 21.5 11 21.5C8.21523 21.5 5.54451 20.3938 3.57538 18.4246C1.60625 16.4555 0.5 13.7848 0.5 11C0.5 8.21523 1.60625 5.54451 3.57538 3.57538C5.54451 1.60625 8.21523 0.5 11 0.5ZM11 5C10.8096 4.99984 10.6212 5.0394 10.4469 5.11615C10.2726 5.1929 10.1162 5.30516 9.98778 5.44575C9.85933 5.58635 9.76161 5.75218 9.70086 5.93268C9.64012 6.11317 9.61769 6.30435 9.635 6.494L10.1825 12.503C10.2037 12.705 10.299 12.892 10.45 13.028C10.6009 13.1639 10.7969 13.2391 11 13.2391C11.2031 13.2391 11.3991 13.1639 11.55 13.028C11.701 12.892 11.7963 12.705 11.8175 12.503L12.3635 6.494C12.3808 6.30447 12.3584 6.11342 12.2978 5.93303C12.2371 5.75264 12.1395 5.58688 12.0112 5.4463C11.8829 5.30573 11.7267 5.19344 11.5526 5.1166C11.3785 5.03976 11.1903 5.00005 11 5ZM11 17C11.3183 17 11.6235 16.8736 11.8485 16.6485C12.0736 16.4235 12.2 16.1183 12.2 15.8C12.2 15.4817 12.0736 15.1765 11.8485 14.9515C11.6235 14.7264 11.3183 14.6 11 14.6C10.6817 14.6 10.3765 14.7264 10.1515 14.9515C9.92643 15.1765 9.8 15.4817 9.8 15.8C9.8 16.1183 9.92643 16.4235 10.1515 16.6485C10.3765 16.8736 10.6817 17 11 17Z"
fill="#E6301B"
/>
</svg>
}
title={__('Cancel Subscription', 'give')}
showHeader={true}
isOpen={isOpen}
handleClose={toggleModal}
>
<p className={'give-donor-dashboard-cancel-modal__description'}>
{__('Are you sure you want to cancel your subscription?', 'give')}
</p>
<div className={'give-donor-dashboard-cancel-modal__buttons'}>
<Button classnames={'give-donor-dashboard-cancel-modal__buttons__button'} disabled={loading} onClick={toggleModal} variant>
{__('Nevermind', 'give')}
</Button>
<Button classnames={'give-donor-dashboard-cancel-modal__buttons__button'} disabled={loading} onClick={handleCancel}>
{__('Yes, cancel', 'give')}
</Button>
</div>

{loading && <DashboardLoadingSpinner />}
</ModalDialog>
);
};

export default SubscriptionCancelModal;
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/* stylelint-disable selector-class-pattern */

/* stylelint-disable selector-class-pattern */

.givewp-modal-wrapper.give-donor-dashboard-cancel-modal {
-webkit-backdrop-filter: blur(4px);
backdrop-filter: blur(4px);
Expand All @@ -21,30 +18,54 @@
}

.givewp-modal-content {
padding: 1.5rem 1.5rem 2rem 1.5rem;
padding: 1.5rem;

.give-donor-dashboard-cancel-modal__description {
margin: 0 0 1.5rem 0;
font-size: 1rem;
font-weight: 500;
color: #1F2937;
}

.give-donor-dashboard-cancel-modal__buttons {
display: flex;
justify-content: space-between;
align-items: center;
gap: 2rem;
width: auto;
margin: 0;

.give-donor-dashboard-cancel-modal__cancel {
&__button.give-donor-dashboard-button.give-donor-dashboard-button--primary {
flex: 1;
display: inline-flex;
align-items: center;
justify-content: center;
max-width: 240px;
padding: 12px 20px;
font-size: 16px;
font-weight: 600;
border-radius: 3px;
color: var(--give-donor-dashboard-accent-color) !important;
background: var(--givewp-shades-white);
box-shadow: none;
border: 1px solid var(--give-donor-dashboard-accent-color);
margin: 0;
cursor: pointer;
background-color: #d92d0b;
border-color: inherit;
color: #fff;

&:before {
display: none;
}

&:hover {
background-color: #F2320C;
}
}

&__button.give-donor-dashboard-button.give-donor-dashboard-button--variant {
flex: 1;
margin: 0;
border-color: #9CA0AF;
color: #000 !important;
filter: none;

&:before {
display: none;
}

&:hover {
background-color: #F9FAFB;
border-color: #9CA0AF;
color: #000 !important;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,12 @@ const AmountControl = ({currency, onChange, value, options, min, max}) => {
return (
<div className="give-donor-dashboard-amount-inputs">
<FieldRow>
<div>
<SelectControl
<SelectControl
label={__('Subscription Amount', 'give')}
options={options}
value={selectValue}
onChange={setSelectValue}
/>
</div>
<div>
{selectValue === CUSTOM_AMOUNT && (
<div className="give-donor-dashboard-currency-control">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ $errorColor: #c91f1f;
color: $errorColor;
}

.give-donor-dashboard-amount-inputs {
display: flex;
flex-direction: column;


.give-donor-dashboard-field-row {
display: flex;
padding: 0;

.give-donor-dashboard-select-control {
display: flex;
min-width: 100%;
margin: 0;
}
}
}

.give-donor-dashboard-currency-control {
margin-top: 10px;

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {useState} from 'react';
import {managePausingSubscriptionWithAPI} from '../utils';

export type pauseDuration = number;
type id = string;

const usePauseSubscription = (id: id) => {
const [loading, setLoading] = useState<boolean>(false);

const handlePause = async (pauseDuration: pauseDuration) => {
setLoading(true);
try {
await managePausingSubscriptionWithAPI({
id,
intervalInMonths: pauseDuration,
});
} catch (error) {
console.error('Error pausing subscription:', error);
} finally {
setLoading(false);
}
};

const handleResume = async () => {
setLoading(true);
try {
await managePausingSubscriptionWithAPI({
id,
action: 'resume',
});
} catch (error) {
console.error('Error resuming subscription:', error);
} finally {
setLoading(false);
}
};

return {
loading,
setLoading,
handlePause,
handleResume,
};
};

export default usePauseSubscription;
Loading

0 comments on commit 50f58cd

Please sign in to comment.