-
-
E-Mail
-
{team.email}
-
+ <>
+
+
+ Information
+
+ Additional information about this team.
+
+
+
+ {team ? (
+
+
+
E-Mail
+
{team.email}
+
+
+
+
+ Team ID
+ {team.id}
+
+
-
- Team ID
- {team.id}
-
-
-
- ) : (
-
- )}
-
-
+ ) : (
+
+ )}
+
+
+
+ >
)
}
diff --git a/src/server/team/team-actions.ts b/src/server/team/team-actions.ts
index bc260e751..806f45851 100644
--- a/src/server/team/team-actions.ts
+++ b/src/server/team/team-actions.ts
@@ -15,7 +15,11 @@ import { logWarning } from '@/lib/clients/logger'
import { returnValidationErrors } from 'next-safe-action'
import { getTeam } from './get-team'
import { SUPABASE_AUTH_HEADERS } from '@/configs/api'
-import { CreateTeamSchema, UpdateTeamNameSchema } from '@/server/team/types'
+import {
+ CreateTeamSchema,
+ UpdateTeamNameSchema,
+ UpdateTeamEmailSchema,
+} from '@/server/team/types'
import { CreateTeamsResponse } from '@/types/billing'
export const updateTeamNameAction = authActionClient
@@ -311,3 +315,30 @@ export const uploadTeamProfilePictureAction = authActionClient
return data
})
+
+export const updateTeamEmailAction = authActionClient
+ .schema(UpdateTeamEmailSchema)
+ .metadata({ actionName: 'updateTeamEmail' })
+ .action(async ({ parsedInput, ctx }) => {
+ const { teamId, email } = parsedInput
+ const { user } = ctx
+
+ const isAuthorized = await checkUserTeamAuthorization(user.id, teamId)
+
+ if (!isAuthorized) {
+ return returnServerError('User is not authorized to update this team')
+ }
+
+ const { data, error } = await supabaseAdmin
+ .from('teams')
+ .update({ email })
+ .eq('id', teamId)
+
+ if (error) {
+ throw error
+ }
+
+ revalidatePath('/dashboard', 'layout')
+
+ return data
+ })
diff --git a/src/server/team/types.ts b/src/server/team/types.ts
index f332cdfa3..a49a24f63 100644
--- a/src/server/team/types.ts
+++ b/src/server/team/types.ts
@@ -38,4 +38,9 @@ const CreateTeamSchema = z.object({
name: TeamNameSchema,
})
-export { UpdateTeamNameSchema, CreateTeamSchema }
+const UpdateTeamEmailSchema = z.object({
+ teamId: z.string().uuid(),
+ email: z.string().email({ message: 'Invalid email address' }),
+})
+
+export { UpdateTeamNameSchema, CreateTeamSchema, UpdateTeamEmailSchema }