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 members who are inactive, former, or on vacation.
+ + {success &&Success!
} + {error &&Error, something went wrong.
} + + {result.member.paused_date ? + + : + + } +