Skip to content

Commit 5d85116

Browse files
committed
Unify: send fields email to backend for both POST and PATCH of groups
1 parent 3f08d32 commit 5d85116

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

app/[orgId]/groups/mockData.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface Group {
66
about?: string;
77
avatar?: string;
88
users: string; // user emails seperated by newline
9+
userEmails: string[];
910
usersCount?: number;
1011
}
1112

@@ -19,6 +20,11 @@ export const mockGroups: Group[] = [
1920
avatar: "https://api.dicebear.com/7.x/initials/svg?seed=ET",
2021
users:
2122
23+
userEmails: [
24+
25+
26+
27+
],
2228
},
2329
{
2430
id: 2,
@@ -28,6 +34,7 @@ export const mockGroups: Group[] = [
2834
about: "Product design and UX team",
2935
avatar: "https://api.dicebear.com/7.x/initials/svg?seed=DT",
3036
37+
3138
},
3239
{
3340
id: 3,
@@ -38,6 +45,11 @@ export const mockGroups: Group[] = [
3845
avatar: "https://api.dicebear.com/7.x/initials/svg?seed=MT",
3946
users:
4047
48+
userEmails: [
49+
50+
51+
52+
],
4153
},
4254
{
4355
id: 4,
@@ -47,5 +59,6 @@ export const mockGroups: Group[] = [
4759
about: "Product management and strategy",
4860
avatar: "https://api.dicebear.com/7.x/initials/svg?seed=PT",
4961
62+
5063
},
5164
];

app/[orgId]/groups/page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,12 @@ export default function GroupsPage() {
140140

141141
// Convert users from string to array of strings (splitting at newlines)
142142
if (typeof groupToSave.users === "string") {
143-
groupToSave.users = groupToSave.users
143+
groupToSave.emails = groupToSave.users
144144
.split("\n")
145145
.map((user) => user.trim())
146146
.filter((user) => user.length > 0); // Remove empty lines
147+
// groupToSave.users = null;
148+
console.log("groupToSave.users", groupToSave.users);
147149
}
148150

149151
console.log("groups", groupToSave);

app/api/orgs/[orgId]/groups/route.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,25 @@ export async function POST(
3232
console.log("request data", requestData);
3333

3434
// Rename 'users' to 'emails' in the request data
35-
const { users, ...restRequestData } = requestData;
36-
const processedData = {
37-
...restRequestData,
38-
emails: users, // Rename 'users' to 'emails'
39-
};
40-
console.log("emails", processedData.emails);
41-
console.log("emails", restRequestData);
35+
// const { users, ...restRequestData } = requestData;
36+
// console.log("*****users", users);
37+
// const processedData = {
38+
// ...restRequestData,
39+
// emails: users, // Rename 'users' to 'emails'
40+
// };
41+
// console.log("emails", processedData.emails);
42+
// console.log("restRequestData", restRequestData);
4243

4344
// Now validate with your schema
44-
const { emails, ...rest } = createGroupSchema.parse(processedData);
45+
const { emails, ...rest } = createGroupSchema.parse(requestData);
4546

46-
console.log("emails", emails);
47-
console.log("rest", rest);
47+
console.log("emails after validation parsed", emails);
48+
console.log("rest after validation parsed", rest);
4849

4950
const group = await groupsService.createGroup(orgId, rest);
5051

5152
if (emails) {
53+
console.log("BAK BAK emails", emails);
5254
const groupWithUserEmails = await groupService.updateGroupMembers(
5355
orgId,
5456
group.id,

0 commit comments

Comments
 (0)