bigbuffet-rw/app/soapbox/features/verification/index.tsx

57 lines
1.5 KiB
TypeScript
Raw Normal View History

import React from 'react';
2022-04-04 08:54:00 -07:00
import { Redirect } from 'react-router-dom';
import { fetchVerificationConfig } from 'soapbox/actions/verification';
import { useAppDispatch, useAppSelector } from 'soapbox/hooks';
2022-04-04 08:54:00 -07:00
import Registration from './registration';
import AgeVerification from './steps/age-verification';
import EmailVerification from './steps/email-verification';
import SmsVerification from './steps/sms-verification';
export enum ChallengeTypes {
2022-04-27 07:11:21 -07:00
EMAIL = 'email',
SMS = 'sms',
AGE = 'age',
2022-04-04 08:54:00 -07:00
}
const verificationSteps = {
email: EmailVerification,
sms: SmsVerification,
age: AgeVerification,
};
const Verification = () => {
const dispatch = useAppDispatch();
2022-04-04 08:54:00 -07:00
const isInstanceReady = useAppSelector((state) => state.verification.instance.get('isReady') === true);
const isRegistrationOpen = useAppSelector(state => state.verification.instance.get('registrations') === true);
const currentChallenge = useAppSelector((state) => state.verification.currentChallenge as ChallengeTypes);
const isVerificationComplete = useAppSelector((state) => state.verification.isComplete);
2022-04-04 08:54:00 -07:00
const StepToRender = verificationSteps[currentChallenge];
React.useEffect(() => {
dispatch(fetchVerificationConfig());
}, []);
if (isInstanceReady && !isRegistrationOpen) {
return <Redirect to='/' />;
}
if (isVerificationComplete) {
return (
<Registration />
);
}
if (!currentChallenge) {
return null;
}
return (
<StepToRender />
);
};
export default Verification;