mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-05 02:58:36 -06:00
fix: broken invite flow (#4387)
Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@ import { sendInviteAcceptedEmail } from "@/modules/email";
|
||||
import { Button } from "@/modules/ui/components/button";
|
||||
import { getServerSession } from "next-auth";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { unstable_after as after } from "next/server";
|
||||
import Link from "next/link";
|
||||
import { DEFAULT_LOCALE, WEBAPP_URL } from "@formbricks/lib/constants";
|
||||
import { deleteInvite, getInvite } from "@formbricks/lib/invite/service";
|
||||
@@ -33,6 +34,37 @@ const Page = async (props) => {
|
||||
|
||||
const isInviteExpired = new Date(invite.expiresAt) < new Date();
|
||||
|
||||
const createMembershipAction = async () => {
|
||||
"use server";
|
||||
|
||||
if (!session || !user) return;
|
||||
|
||||
await createMembership(invite.organizationId, session.user.id, {
|
||||
accepted: true,
|
||||
role: invite.role,
|
||||
});
|
||||
await deleteInvite(inviteId);
|
||||
await sendInviteAcceptedEmail(
|
||||
invite.creator.name ?? "",
|
||||
user?.name ?? "",
|
||||
invite.creator.email,
|
||||
user?.locale ?? DEFAULT_LOCALE
|
||||
);
|
||||
await updateUser(session.user.id, {
|
||||
notificationSettings: {
|
||||
...user.notificationSettings,
|
||||
alert: user.notificationSettings.alert ?? {},
|
||||
weeklySummary: user.notificationSettings.weeklySummary ?? {},
|
||||
unsubscribedOrganizationIds: Array.from(
|
||||
new Set([
|
||||
...(user.notificationSettings?.unsubscribedOrganizationIds || []),
|
||||
invite.organizationId,
|
||||
])
|
||||
),
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
if (isInviteExpired) {
|
||||
return (
|
||||
<ContentLayout
|
||||
@@ -70,32 +102,9 @@ const Page = async (props) => {
|
||||
</ContentLayout>
|
||||
);
|
||||
} else {
|
||||
await createMembership(invite.organizationId, session.user.id, {
|
||||
accepted: true,
|
||||
role: invite.role,
|
||||
after(async () => {
|
||||
await createMembershipAction();
|
||||
});
|
||||
await deleteInvite(inviteId);
|
||||
|
||||
await sendInviteAcceptedEmail(
|
||||
invite.creator.name ?? "",
|
||||
user?.name ?? "",
|
||||
invite.creator.email,
|
||||
user?.locale ?? DEFAULT_LOCALE
|
||||
);
|
||||
await updateUser(session.user.id, {
|
||||
notificationSettings: {
|
||||
...user.notificationSettings,
|
||||
alert: user.notificationSettings.alert ?? {},
|
||||
weeklySummary: user.notificationSettings.weeklySummary ?? {},
|
||||
unsubscribedOrganizationIds: Array.from(
|
||||
new Set([
|
||||
...(user.notificationSettings?.unsubscribedOrganizationIds || []),
|
||||
invite.organizationId,
|
||||
])
|
||||
),
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<ContentLayout
|
||||
headline={t("auth.invite.welcome_to_organization")}
|
||||
|
||||
Reference in New Issue
Block a user