diff --git a/apps/web/README.md b/apps/web/README.md index 56f58dec10..71336e6a28 100644 --- a/apps/web/README.md +++ b/apps/web/README.md @@ -61,7 +61,7 @@ To get the project running locally on your machine you need to have the followin **You can now access the app on [https://localhost:3000](https://localhost:3000)**. You will be automatically redirected to the login. To use your local installation of formbricks, create a new account. - For viewing the confirmation email and other emails the system sends you, you can access mailhog at [https://localhost:8025](https://localhost:8025) + For viewing the confirmation email and other emails the system sends you, you can access mailhog at [http://localhost:8025](http://localhost:8025) ### Build diff --git a/apps/web/app/components.tsx b/apps/web/app/HomeRedirect.tsx similarity index 55% rename from apps/web/app/components.tsx rename to apps/web/app/HomeRedirect.tsx index ac6047bfd0..299d98db1f 100644 --- a/apps/web/app/components.tsx +++ b/apps/web/app/HomeRedirect.tsx @@ -1,22 +1,35 @@ "use client"; +import LoadingSpinner from "@/components/shared/LoadingSpinner"; import { fetcher } from "@formbricks/lib/fetcher"; +import type { Session } from "next-auth"; import { signOut } from "next-auth/react"; import { redirect } from "next/navigation"; import { useEffect } from "react"; import useSWR from "swr"; -import LoadingSpinner from "@/components/shared/LoadingSpinner"; -export function HomeRedirect() { +interface HomeRedirectProps { + session: Session; +} + +export function HomeRedirect({ session }: HomeRedirectProps) { const { data, error } = useSWR(`/api/v1/environments/find-first`, fetcher); useEffect(() => { - if (data && !error) { - return redirect(`/environments/${data.id}`); - } else if (error) { - console.error(error); + if (session) { + if (!session.user?.onboardingDisplayed) { + return redirect(`/onboarding`); + } + + if (data && !error) { + return redirect(`/environments/${data.id}`); + } else if (error) { + console.error(error); + } + } else { + return redirect(`/auth/login`); } - }, [data, error]); + }, [data, error, session]); if (error) { setTimeout(() => { diff --git a/apps/web/app/environments/[environmentId]/surveys/SurveyList.tsx b/apps/web/app/environments/[environmentId]/surveys/SurveyList.tsx index 3a52147d1a..58fbc01462 100644 --- a/apps/web/app/environments/[environmentId]/surveys/SurveyList.tsx +++ b/apps/web/app/environments/[environmentId]/surveys/SurveyList.tsx @@ -1,5 +1,6 @@ "use client"; +import { Template } from "@/../../packages/types/templates"; import DeleteDialog from "@/components/shared/DeleteDialog"; import { DropdownMenu, @@ -10,7 +11,8 @@ import { } from "@/components/shared/DropdownMenu"; import LoadingSpinner from "@/components/shared/LoadingSpinner"; import SurveyStatusIndicator from "@/components/shared/SurveyStatusIndicator"; -import { deleteSurvey, duplicateSurvey, useSurveys } from "@/lib/surveys/surveys"; +import { useProfile } from "@/lib/profile"; +import { createSurvey, deleteSurvey, useSurveys, duplicateSurvey } from "@/lib/surveys/surveys"; import { Badge, ErrorComponent } from "@formbricks/ui"; import { PlusIcon } from "@heroicons/react/24/outline"; import { @@ -25,12 +27,15 @@ import Link from "next/link"; import { useRouter } from "next/navigation"; import { useState } from "react"; import toast from "react-hot-toast"; +import TemplateList from "./templates/TemplateList"; export default function SurveysList({ environmentId }) { const router = useRouter(); const { surveys, mutateSurveys, isLoadingSurveys, isErrorSurveys } = useSurveys(environmentId); + const { isLoadingProfile, isErrorProfile } = useProfile(); const [isDeleteDialogOpen, setDeleteDialogOpen] = useState(false); + const [isCreateSurveyLoading, setIsCreateSurveyLoading] = useState(false); const [activeSurvey, setActiveSurvey] = useState("" as any); const [activeSurveyIdx, setActiveSurveyIdx] = useState("" as any); @@ -39,6 +44,17 @@ export default function SurveysList({ environmentId }) { router.push(`/environments/${environmentId}/surveys/templates`); }; + const newSurveyFromTemplate = async (template: Template) => { + setIsCreateSurveyLoading(true); + try { + const survey = await createSurvey(environmentId, template.preset); + router.push(`/environments/${environmentId}/surveys/${survey.id}/edit`); + } catch (e) { + toast.error("An error occured creating a new survey"); + setIsCreateSurveyLoading(false); + } + }; + const deleteSurveyAction = async (survey, surveyIdx) => { try { await deleteSurvey(environmentId, survey.id); @@ -63,21 +79,45 @@ export default function SurveysList({ environmentId }) { } }; - if (isLoadingSurveys) { + if (isLoadingSurveys || isLoadingProfile) { return ; } - if (isErrorSurveys) { + if (isErrorSurveys || isErrorProfile) { return ; } + if (surveys.length === 0) { + return ( +
+ {isCreateSurveyLoading ? ( + + ) : ( + <> +
+

+ You're all set! Time to create your first survey. +

+
+ { + newSurveyFromTemplate(template); + }} + /> + + )} +
+ ); + } + return ( <>