import { useEffect, useState } from "react"; import toast from "react-hot-toast"; import styled from "styled-components"; import StyledRadio from "../../../common/component/styled/Radio"; import StyledButton from "../../../common/component/styled/Button"; import { useGetLoginConfigQuery, useUpdateLoginConfigMutation } from "../../../app/services/server"; import { WhoCanSignUp } from "../../../types/server"; import { useTranslation } from "react-i18next"; import { useWizard } from "react-use-wizard"; export default function SignUpSetting() { const { t } = useTranslation("welcome"); const { t: st } = useTranslation("setting"); const { nextStep } = useWizard(); const { data: loginConfig, refetch } = useGetLoginConfigQuery(); const [updateLoginConfig, { isSuccess, error }] = useUpdateLoginConfigMutation(); const [value, setValue] = useState(); useEffect(() => { refetch(); }, []); // Sync to `value` when `loginConfig` is fetched useEffect(() => { if (loginConfig) { console.log("login config", loginConfig.who_can_sign_up); setValue(loginConfig.who_can_sign_up); } }, [loginConfig]); // Display error useEffect(() => { if (error === undefined) return; toast.error(`Failed to update sign up rule: ${error.data}`); }, [error]); // Increment `step` when updating has completed useEffect(() => { if (isSuccess) nextStep(); }, [isSuccess]); const StyledWrapper = styled.div` /* > form { width: 512px; } > .button { width: 124px; height: 44px; margin-top: 24px; } */ `; return ( {t("onboarding.invite_title")} {t("onboarding.invite_desc")} {value && } { // nextStep(); if (loginConfig !== undefined) { if (loginConfig.who_can_sign_up !== value) { updateLoginConfig({ ...loginConfig, who_can_sign_up: value }); } else { nextStep(); } } }} > {t("onboarding.confirm")} ); }