From b214dc230f8f4155e0a918b069b5ca50137b13c4 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 20 Jan 2020 02:25:58 +0000 Subject: [PATCH] Add UI for pausing and unpausing members --- webclient/src/Admin.js | 83 +++++++++++++++++++++++++++++++++++++++- webclient/src/Members.js | 6 ++- 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/webclient/src/Admin.js b/webclient/src/Admin.js index bcbc20d..d6ba6b6 100644 --- a/webclient/src/Admin.js +++ b/webclient/src/Admin.js @@ -170,13 +170,19 @@ function AdminCardDetail(props) { export function AdminMemberCards(props) { const { token, result, refreshResult } = props; const cards = result.cards; - const [dimmed, setDimmed] = useState(result.member.paused_date && cards.length); + const startDimmed = Boolean(result.member.paused_date && cards.length); + const [dimmed, setDimmed] = useState(startDimmed); const [input, setInput] = useState({ active_status: 'card_active' }); const [error, setError] = useState(false); const [loading, setLoading] = useState(false); const [success, setSuccess] = useState(false); const { id } = useParams(); + useEffect(() => { + const startDimmed = Boolean(result.member.paused_date && cards.length); + setDimmed(startDimmed); + }, [result.member]); + const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value }); const handleUpload = (e, v) => setInput({ ...input, [v.name]: e.target.files[0] }); const handleChange = (e) => handleValues(e, e.currentTarget); @@ -271,6 +277,77 @@ export function AdminMemberCards(props) { ); }; +export function AdminMemberPause(props) { + const { token, result, refreshResult } = props; + const [error, setError] = useState(false); + const [loading, setLoading] = useState(false); + const [success, setSuccess] = useState(false); + const [yousure, setYousure] = useState(false); + const { id } = useParams(); + + useEffect(() => { + setLoading(false); + }, [result.member]); + + const handlePause = (e) => { + if (yousure) { + setLoading(true); + setSuccess(false); + requester('/members/' + id + '/pause/', 'GET', token) + .then(res => { + setYousure(false); + setSuccess(true); + setError(false); + refreshResult(); + }) + .catch(err => { + setLoading(false); + console.log(err); + setError(true); + }); + } else { + setYousure(true); + } + }; + + const handleUnpause = (e) => { + setLoading(true); + setSuccess(false); + requester('/members/' + id + '/unpause/', 'GET', token) + .then(res => { + setSuccess(true); + setError(false); + refreshResult(); + }) + .catch(err => { + setLoading(false); + console.log(err); + setError(true); + }); + }; + + return ( +
+
Pause / Unpause Membership
+ +

Pause members who are inactive, former, or on vacation.

+ + {success &&

Success!

} + {error &&

Error, something went wrong.

} + + {result.member.paused_date ? + + : + + } +
+ ); +}; + export function AdminMemberForm(props) { const { token, result, refreshResult } = props; const [input, setInput] = useState(result.member); @@ -279,6 +356,10 @@ export function AdminMemberForm(props) { const [success, setSuccess] = useState(false); const { id } = useParams(); + useEffect(() => { + setInput(result.member); + }, [result.member]); + const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value }); const handleUpload = (e, v) => setInput({ ...input, [v.name]: e.target.files[0] }); const handleChange = (e) => handleValues(e, e.currentTarget); diff --git a/webclient/src/Members.js b/webclient/src/Members.js index de5d28a..e536a89 100644 --- a/webclient/src/Members.js +++ b/webclient/src/Members.js @@ -4,7 +4,7 @@ import './light.css'; import { Button, Container, Divider, Dropdown, Form, Grid, Header, Icon, Image, Input, Item, Menu, Message, Segment, Table } from 'semantic-ui-react'; import { isAdmin, BasicTable, staticUrl, requester } from './utils.js'; import { NotFound, PleaseLogin } from './Misc.js'; -import { AdminMemberInfo, AdminMemberForm, AdminMemberCards, AdminTransactions } from './Admin.js'; +import { AdminMemberInfo, AdminMemberPause, AdminMemberForm, AdminMemberCards, AdminTransactions } from './Admin.js'; export function Members(props) { const [response, setResponse] = useState(false); @@ -127,6 +127,10 @@ export function MemberDetail(props) { {isAdmin(user) && } + + {isAdmin(user) && + + }