AuthorizeRejectButtons: fix onReject never being called
This commit is contained in:
parent
9367b16200
commit
3b8f43f02d
|
@ -14,7 +14,11 @@ const AuthorizeRejectButtons: React.FC<IAuthorizeRejectButtons> = ({ onAuthorize
|
||||||
const [state, setState] = useState<'authorizing' | 'rejecting' | 'authorized' | 'rejected' | 'pending'>('pending');
|
const [state, setState] = useState<'authorizing' | 'rejecting' | 'authorized' | 'rejected' | 'pending'>('pending');
|
||||||
const timeout = useRef<NodeJS.Timeout>();
|
const timeout = useRef<NodeJS.Timeout>();
|
||||||
|
|
||||||
function handleAction(present: 'authorizing' | 'rejecting', past: 'authorized' | 'rejected'): void {
|
function handleAction(
|
||||||
|
present: 'authorizing' | 'rejecting',
|
||||||
|
past: 'authorized' | 'rejected',
|
||||||
|
action: () => Promise<unknown> | unknown,
|
||||||
|
): void {
|
||||||
if (state === present) {
|
if (state === present) {
|
||||||
if (timeout.current) {
|
if (timeout.current) {
|
||||||
clearTimeout(timeout.current);
|
clearTimeout(timeout.current);
|
||||||
|
@ -24,7 +28,7 @@ const AuthorizeRejectButtons: React.FC<IAuthorizeRejectButtons> = ({ onAuthorize
|
||||||
setState(present);
|
setState(present);
|
||||||
timeout.current = setTimeout(async () => {
|
timeout.current = setTimeout(async () => {
|
||||||
try {
|
try {
|
||||||
await onAuthorize();
|
await action();
|
||||||
setState(past);
|
setState(past);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -33,8 +37,8 @@ const AuthorizeRejectButtons: React.FC<IAuthorizeRejectButtons> = ({ onAuthorize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleAuthorize = async () => handleAction('authorizing', 'authorized');
|
const handleAuthorize = async () => handleAction('authorizing', 'authorized', onAuthorize);
|
||||||
const handleReject = async () => handleAction('rejecting', 'rejected');
|
const handleReject = async () => handleAction('rejecting', 'rejected', onReject);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
|
|
Loading…
Reference in New Issue