import { Affix, Button, Card, Col, Divider, Flex, Form, Row, Segmented, Skeleton, Typography, notification, } from "antd"; import { useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; import { AppStyle, Constants, EncodeStringToBase64, myFetch, showInputsInvalidNotification, showUnkownErrorNotification, } from "../../utils"; import { MyCompanyAddressFormInput, MyCompanyNameFormInput, MyEmailFormInput, MyPasswordFormInput, MyUsernameFormInput, } from "../../Components/MyFormInputs"; import { MyRecaptcha, PrivacyPolicyCheckbox } from "."; import MyAppLogo from "../../Components/MyAppLogo"; import { CheckOutlined } from "@ant-design/icons"; import { RequestState } from "../../Components/MyRequestStateItem"; /* const SignUpStep = { SIGN_UP: 1, PENDING_EMAIL_VERIFICATION: 2, }; */ export default function SignUp({ paymentPlan }) { const [notificationApi, notificationContextHolder] = notification.useNotification(); const { t, i18n } = useTranslation(); const navigate = useNavigate(); const [form] = Form.useForm(); //const [step, setStep] = useState(SignUpStep.SIGN_UP); /* if (step === SignUpStep.PENDING_EMAIL_VERIFICATION) { return ; } */ return ( <> {notificationContextHolder} ); } function AccountDetails({ t, form }) { return (
); } export function ChoosenProduct({ t, paymentPlan, extra }) { return ( {Constants.APP_NAME} - {Constants.PAYMENT_PLAN[paymentPlan].name} {[ ...Array( t( `authentication.signUp.choosenProduct.products.${paymentPlan}.featuresCount` ) ), ].map((_, index) => { return ( {t( `authentication.signUp.choosenProduct.products.${paymentPlan}.features.${index}` )} ); })} ); } function CostSummary({ notificationApi, paymentPlan, form }) { const { t, i18n } = useTranslation(); const [isRequesting, setIsRequesting] = useState(RequestState.INIT); const recaptchaRef = useRef(null); const recaptchaValueRef = useRef(null); const [prices, setPrices] = useState(null); const [segmentedValue, setSegmentedValue] = useState(1); const showErrorNotification = (errStatus) => { if (errStatus === 400) { notificationApi["error"]({ message: t("authentication.signUp.request.400.title"), description: t("authentication.signUp.request.400.description"), }); } }; const handleSubmit = () => { form .validateFields() .then((values) => { setIsRequesting(RequestState.REQUESTING); myFetch({ url: `/user/auth/signup`, method: "POST", body: { companyName: values.companyName, email: values.email.toLocaleLowerCase(), password: EncodeStringToBase64(values.password), username: values.username, language: i18n.language, rememberMe: true, recaptcha: recaptchaValueRef.current, paymentPlan: paymentPlan, paymentInterval: segmentedValue, companyAddress: values.companyAddress, }, notificationApi: notificationApi, t: t, }) .then((data) => { setIsRequesting(RequestState.NOTHING); localStorage.setItem("tmp_session", data.XAuthorization); window.location.href = data.redirectUrl; }) .catch((errStatus) => { recaptchaRef.current.reset(); showErrorNotification(errStatus); setIsRequesting(false); }); }) .catch(() => { recaptchaRef.current.reset(); showInputsInvalidNotification(notificationApi, t); setIsRequesting(false); }); }; useEffect(() => { myFetch({ url: `/payment/prices/${paymentPlan}`, method: "GET", }) .then((data) => { setIsRequesting(RequestState.NOTHING); setPrices(data.prices); }) .catch(() => showUnkownErrorNotification(notificationApi, t)); }, []); const formatPrice = (price) => { return (price / 100).toLocaleString("de-DE", { style: "currency", currency: "EUR", }); }; const price = prices ? prices[segmentedValue].unit_amount : 0; const totalNet = formatPrice(price); const vat = formatPrice((price / 100) * 19); const totalAmount = formatPrice(price + (price / 100) * 19); return (
setSegmentedValue(v)} />
{Constants.APP_NAME} - {Constants.PAYMENT_PLAN[paymentPlan].name}
{t("authentication.signUp.costSummary.totalNet")} {isRequesting === RequestState.INIT ? ( ) : ( {totalNet} )} {t("authentication.signUp.costSummary.vat")} {isRequesting === RequestState.INIT ? ( ) : ( {vat} )} {t("authentication.signUp.costSummary.totalAmount")} {isRequesting === RequestState.INIT ? ( ) : ( {totalAmount} )}
); }