Merge branch 'main' into enterprise-license

staging
kodiakhq[bot] 2022-04-12 17:12:23 +00:00 committed by GitHub
commit 7db55ec396
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 10 deletions

View File

@ -223,7 +223,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const reqBody = req.body as BookingCreateBody;
// handle dynamic user
const dynamicUserList = getUsernameList(reqBody.user as string);
const dynamicUserList = getUsernameList(reqBody?.user);
const eventTypeSlug = reqBody.eventTypeSlug;
const eventTypeId = reqBody.eventTypeId;
const tAttendees = await getTranslation(reqBody.language ?? "en", "common");

View File

@ -139,15 +139,29 @@ export const getUsernameSlugLink = ({ users, slug }: UsernameSlugLinkProps): str
return slugLink;
};
export const getUsernameList = (users: string): string[] => {
return users
?.toLowerCase()
.replace(/ /g, "+")
.replace(/%20/g, "+")
.split("+")
.filter((el) => {
return el.length != 0;
});
export const getUsernameList = (users: string | string[] | undefined): string[] => {
if (!users) {
return [];
}
if (!(users instanceof Array)) {
users = [users];
}
const allUsers: string[] = [];
// Multiple users can come in case of a team round-robin booking and in that case dynamic link won't be a user.
// So, even though this code handles even if individual user is dynamic link, that isn't a possibility right now.
users.forEach((user) => {
allUsers.push(
...user
?.toLowerCase()
.replace(/ /g, "+")
.replace(/%20/g, "+")
.split("+")
.filter((el) => {
return el.length != 0;
})
);
});
return allUsers;
};
export default defaultEvents;