-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(saas): Add User to waitlist logic
- Loading branch information
1 parent
b756a6a
commit 9d23608
Showing
3 changed files
with
99 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"use server"; | ||
import { waitlistUsers, waitlistUsersSchema } from "@/server/db/schema"; | ||
import { type z } from "zod"; | ||
import { db } from "@/server/db"; | ||
|
||
type AddUserToWaitlistMutationProps = z.infer<typeof waitlistUsersSchema>; | ||
|
||
export async function addUserToWaitlistMutation({ | ||
name, | ||
email, | ||
}: AddUserToWaitlistMutationProps) { | ||
const parseData = await waitlistUsersSchema.safeParseAsync({ | ||
name, | ||
email, | ||
}); | ||
|
||
if (!parseData.success) { | ||
return { | ||
success: false, | ||
error: parseData.error.message, | ||
}; | ||
} | ||
|
||
const { data } = parseData; | ||
|
||
try { | ||
await db | ||
.insert(waitlistUsers) | ||
.values(data) | ||
.onConflictDoUpdate({ | ||
target: waitlistUsers.email, | ||
set: { name: data.name }, | ||
}) | ||
.execute(); | ||
|
||
return { | ||
success: true, | ||
}; | ||
} catch (error) { | ||
return { | ||
success: false, | ||
error: "Something went wrong, please try again later", | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters