Skip to content

Commit

Permalink
Merge pull request #1157 from Shelf-nu/1156-fix-dont-prompt-user-to-c…
Browse files Browse the repository at this point in the history
…hoose-plan-when-registering-via-a-team-workspace-invite

improvement: add flag to user so we know if they registered via invite
  • Loading branch information
DonKoko committed Jul 11, 2024
2 parents 53bf315 + 6f34566 commit bb79871
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- DropForeignKey
ALTER TABLE "Qr" DROP CONSTRAINT "Qr_userId_fkey";

-- AlterTable
ALTER TABLE "User" ADD COLUMN "createdWithInvite" BOOLEAN NOT NULL DEFAULT false;

-- AddForeignKey
ALTER TABLE "Qr" ADD CONSTRAINT "Qr_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
21 changes: 11 additions & 10 deletions app/database/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ model Image {
}

model User {
id String @id @default(cuid())
email String @unique
username String @unique @default(cuid())
firstName String?
lastName String?
profilePicture String?
usedFreeTrial Boolean @default(false)
onboarded Boolean @default(false)
customerId String? @unique // Stripe customer id
sso Boolean @default(false)
id String @id @default(cuid())
email String @unique
username String @unique @default(cuid())
firstName String?
lastName String?
profilePicture String?
usedFreeTrial Boolean @default(false)
onboarded Boolean @default(false)
customerId String? @unique // Stripe customer id
sso Boolean @default(false)
createdWithInvite Boolean @default(false) // Set to true if the user was created by being invited to a workspace
// Datetime
createdAt DateTime @default(now())
Expand Down
1 change: 1 addition & 0 deletions app/modules/invite/service.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ export async function updateInviteStatus({
roles: invite.roles,
password,
firstName: invite.inviteeTeamMember.name,
createdWithInvite: true,
});

Object.assign(data, {
Expand Down
7 changes: 7 additions & 0 deletions app/modules/user/service.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,13 @@ export async function createUserOrAttachOrg({
roles,
password,
firstName,
createdWithInvite = false,
}: Pick<User, "email" | "firstName"> & {
organizationId: Organization["id"];
roles: OrganizationRoles[];
password: string;
/** We mark */
createdWithInvite: boolean;
}) {
try {
const shelfUser = await db.user.findFirst({ where: { email } });
Expand Down Expand Up @@ -156,6 +159,7 @@ export async function createUserOrAttachOrg({
organizationId,
roles,
firstName,
createdWithInvite,
});
}

Expand Down Expand Up @@ -422,6 +426,7 @@ export async function createUser(
firstName?: User["firstName"];
lastName?: User["lastName"];
isSSO?: boolean;
createdWithInvite?: boolean;
}
) {
const {
Expand All @@ -433,6 +438,7 @@ export async function createUser(
firstName,
lastName,
isSSO,
createdWithInvite,
} = payload;

/**
Expand All @@ -451,6 +457,7 @@ export async function createUser(
username,
firstName,
lastName,
createdWithInvite,
roles: {
connect: {
name: Roles["USER"],
Expand Down
5 changes: 4 additions & 1 deletion app/routes/_welcome+/onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,14 @@ export async function action({ context, request }: ActionFunctionArgs) {
});
}

/** If organizationId is passed, that means the user comes from an invite */
const { organizationId } = parseData(
formData,
z.object({ organizationId: z.string().optional() })
);

const createdWithInvite = !!organizationId || user.createdWithInvite;

const headers = [];

if (organizationId) {
Expand All @@ -182,7 +185,7 @@ export async function action({ context, request }: ActionFunctionArgs) {
);
}

return redirect(organizationId ? `/assets` : `/welcome`, {
return redirect(createdWithInvite ? `/assets` : `/welcome`, {
headers,
});
} catch (cause) {
Expand Down

0 comments on commit bb79871

Please sign in to comment.