@@ -6,12 +6,18 @@ import { captureException } from "@sentry/nextjs";
6
6
import * as Sentry from "@sentry/nextjs" ;
7
7
import { z } from "zod" ;
8
8
9
- import type { Communities , CommunitiesId , CommunityMemberships , Users , UsersId } from "db/public" ;
9
+ import type {
10
+ Communities ,
11
+ CommunitiesId ,
12
+ CommunityMemberships ,
13
+ FormsId ,
14
+ Users ,
15
+ UsersId ,
16
+ } from "db/public" ;
10
17
import { AuthTokenType , MemberRole } from "db/public" ;
11
18
import { logger } from "logger" ;
12
19
13
- import type { Prettify , XOR } from "../types" ;
14
- import type { SafeUser } from "~/lib/server/user" ;
20
+ import type { Prettify } from "../types" ;
15
21
import { compiledSignupFormSchema } from "~/app/components/Signup/schema" ;
16
22
import { db } from "~/kysely/database" ;
17
23
import { isUniqueConstraintError } from "~/kysely/errors" ;
@@ -29,9 +35,8 @@ import {
29
35
import { LAST_VISITED_COOKIE } from "../../app/components/LastVisitedCommunity/constants" ;
30
36
import { findCommunityBySlug } from "../server/community" ;
31
37
import * as Email from "../server/email" ;
32
- import { insertCommunityMember , selectCommunityMember } from "../server/member" ;
38
+ import { insertCommunityMemberships , selectCommunityMemberships } from "../server/member" ;
33
39
import { invalidateTokensForUser } from "../server/token" ;
34
- import { isClientExceptionOptions } from "../serverActions" ;
35
40
import { SignupErrors } from "./errors" ;
36
41
import { getLoginData } from "./loginData" ;
37
42
@@ -214,22 +219,24 @@ const addUserToCommunity = defineServerAction(async function addUserToCommunity(
214
219
* @default MemberRole.contributor
215
220
*/
216
221
role ?: MemberRole ;
222
+ forms : FormsId [ ] ;
217
223
} ) {
218
- const existingMembership = await selectCommunityMember ( {
224
+ const existingMemberships = await selectCommunityMemberships ( {
219
225
userId : props . userId ,
220
226
communityId : props . communityId ,
221
227
} ) . executeTakeFirst ( ) ;
222
228
223
- if ( existingMembership ) {
229
+ if ( existingMemberships ) {
224
230
return {
225
231
error : "User already in community" ,
226
232
} ;
227
233
}
228
234
229
- const newMembership = await insertCommunityMember ( {
235
+ const newMembership = await insertCommunityMemberships ( {
230
236
userId : props . userId ,
231
237
communityId : props . communityId ,
232
238
role : props . role ?? MemberRole . contributor ,
239
+ forms : props . forms ,
233
240
} ) . executeTakeFirstOrThrow ( ) ;
234
241
235
242
return {
@@ -268,10 +275,11 @@ export const publicJoinCommunity = defineServerAction(async function joinCommuni
268
275
return SignupErrors . NOT_ALLOWED ( { communityName : community . name } ) ;
269
276
}
270
277
271
- const member = await insertCommunityMember ( {
278
+ const member = await insertCommunityMemberships ( {
272
279
userId : user . id ,
273
280
communityId : community . id ,
274
281
role : toBeGrantedRole ,
282
+ forms : [ ] , // TODO: fetch these from invite token as well maybe?
275
283
} ) . executeTakeFirstOrThrow ( ) ;
276
284
277
285
// don't redirect, better to do it client side, better ux
@@ -349,11 +357,12 @@ export const publicSignup = defineServerAction(async function signup(props: {
349
357
} ) ;
350
358
351
359
// TODO: add to community
352
- const newMember = await insertCommunityMember (
360
+ const newMember = await insertCommunityMemberships (
353
361
{
354
362
userId : newUser . id ,
355
363
communityId : community . id ,
356
364
role : props . role ?? MemberRole . contributor ,
365
+ forms : [ ] , //TODO: make these customizable
357
366
} ,
358
367
trx
359
368
) . executeTakeFirstOrThrow ( ) ;
0 commit comments