diff --git a/src/routes/onboarding/index.tsx b/src/routes/onboarding/index.tsx index e3dc1937..6ce29a8b 100644 --- a/src/routes/onboarding/index.tsx +++ b/src/routes/onboarding/index.tsx @@ -2,12 +2,12 @@ import React, { useState } from "react"; import { Helmet } from "react-helmet"; import { useWizard, Wizard } from 'react-use-wizard'; -import WelcomePage from "./steps/welcomePage"; -import ServerName from "./steps/serverName"; -import AdminAccount from "./steps/adminAccount"; -import WhoCanSignUp from "./steps/whoCanSignUp"; -import InviteLink from "./steps/inviteLink"; -import DonePage from "./steps/donePage"; +import WelcomePage from "./steps/welcome-page"; +import ServerName from "./steps/server-name"; +import AdminAccount from "./steps/admin-account"; +import WhoCanSignUp from "./steps/who-can-sign-up"; +import InviteLink from "./steps/invite-link"; +import DonePage from "./steps/done-page"; import steps from "./steps"; import StyledOnboardingPage from "./styled"; import { useTranslation } from "react-i18next"; diff --git a/src/routes/onboarding/steps/UpdateFrontendURL.tsx b/src/routes/onboarding/steps/UpdateFrontendURL.tsx new file mode 100644 index 00000000..317eb916 --- /dev/null +++ b/src/routes/onboarding/steps/UpdateFrontendURL.tsx @@ -0,0 +1,53 @@ +import { useState, useEffect, ChangeEvent } from 'react'; +import { toast } from "react-hot-toast"; +import StyledInput from "../../../common/component/styled/Input"; +import StyledButton from "../../../common/component/styled/Button"; +import { useGetFrontendUrlQuery, useUpdateFrontendUrlMutation } from "../../../app/services/server"; +import InfoIcon from '../../../assets/icons/info.svg'; +import { useTranslation } from 'react-i18next'; + + +type Props = { + refreshInviteLink: () => void +} + +const UpdateFrontendURL = ({ refreshInviteLink }: Props) => { + const { t } = useTranslation("welcome", { keyPrefix: "onboarding" }); + const { t: ct } = useTranslation(); + const [updateUrl, { isSuccess, isLoading }] = useUpdateFrontendUrlMutation(); + const { data, isSuccess: getUrlSuccess } = useGetFrontendUrlQuery(); + const [frontUrl, setFrontUrl] = useState(location.origin); + const handleUpdateUrl = (evt: ChangeEvent) => { + setFrontUrl(evt.target.value); + }; + const updateFrontUrl = () => { + updateUrl(frontUrl); + }; + useEffect(() => { + if (getUrlSuccess && data) { + setFrontUrl(data); + } + }, [getUrlSuccess]); + useEffect(() => { + if (isSuccess) { + refreshInviteLink(); + toast.success("Update Successfully!"); + } + }, [isSuccess]); + return ( +
+ +
+ {t("update_domain_tip")} +
+ + + {ct("action.update")} + +
+
+
+ ); +}; + +export default UpdateFrontendURL; \ No newline at end of file diff --git a/src/routes/onboarding/steps/adminAccount.tsx b/src/routes/onboarding/steps/admin-account.tsx similarity index 100% rename from src/routes/onboarding/steps/adminAccount.tsx rename to src/routes/onboarding/steps/admin-account.tsx diff --git a/src/routes/onboarding/steps/donePage.tsx b/src/routes/onboarding/steps/done-page.tsx similarity index 100% rename from src/routes/onboarding/steps/donePage.tsx rename to src/routes/onboarding/steps/done-page.tsx diff --git a/src/routes/onboarding/steps/inviteLink.tsx b/src/routes/onboarding/steps/invite-link.tsx similarity index 50% rename from src/routes/onboarding/steps/inviteLink.tsx rename to src/routes/onboarding/steps/invite-link.tsx index 29ec905c..578bac21 100644 --- a/src/routes/onboarding/steps/inviteLink.tsx +++ b/src/routes/onboarding/steps/invite-link.tsx @@ -1,33 +1,18 @@ + +import { useTranslation } from "react-i18next"; +import { useWizard } from "react-use-wizard"; import StyledInput from "../../../common/component/styled/Input"; import StyledButton from "../../../common/component/styled/Button"; import useInviteLink from "../../../common/hook/useInviteLink"; -import { useTranslation } from "react-i18next"; -import { useWizard } from "react-use-wizard"; -import { ChangeEvent, useState, useEffect } from "react"; -import { useUpdateFrontendUrlMutation } from "../../../app/services/server"; -import { toast } from "react-hot-toast"; -import InfoIcon from '../../../assets/icons/info.svg'; import ServerVersionChecker from "../../../common/component/ServerVersionChecker"; +import UpdateFrontendURL from "./UpdateFrontendURL"; export default function InviteLink() { - const [updateUrl, { isSuccess, isLoading }] = useUpdateFrontendUrlMutation(); const { t } = useTranslation("welcome", { keyPrefix: "onboarding" }); const { t: ct } = useTranslation(); const { nextStep } = useWizard(); const { link, linkCopied, copyLink, generateNewLink } = useInviteLink(); - const [frontUrl, setFrontUrl] = useState(location.origin); - const handleUpdateUrl = (evt: ChangeEvent) => { - setFrontUrl(evt.target.value); - }; - const updateFrontUrl = () => { - updateUrl(frontUrl); - }; - useEffect(() => { - if (isSuccess) { - generateNewLink(); - toast.success("Update Successfully!"); - } - }, [isSuccess]); + return (
{t("invite_title")} @@ -42,19 +27,8 @@ export default function InviteLink() { {t("done")} - -
- -
- {t("update_domain_tip")} -
- - - {ct("action.update")} - -
-
-
+ +
); diff --git a/src/routes/onboarding/steps/serverName.tsx b/src/routes/onboarding/steps/server-name.tsx similarity index 100% rename from src/routes/onboarding/steps/serverName.tsx rename to src/routes/onboarding/steps/server-name.tsx diff --git a/src/routes/onboarding/steps/welcomePage.tsx b/src/routes/onboarding/steps/welcome-page.tsx similarity index 100% rename from src/routes/onboarding/steps/welcomePage.tsx rename to src/routes/onboarding/steps/welcome-page.tsx diff --git a/src/routes/onboarding/steps/whoCanSignUp.tsx b/src/routes/onboarding/steps/who-can-sign-up.tsx similarity index 100% rename from src/routes/onboarding/steps/whoCanSignUp.tsx rename to src/routes/onboarding/steps/who-can-sign-up.tsx