Reduce Payload for Event-Types[Avoid 500] (#2627)
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
This commit is contained in:
parent
34d3aac4b0
commit
cf346f6aa3
4 changed files with 84 additions and 51 deletions
|
@ -80,6 +80,10 @@ const nextConfig = {
|
||||||
source: "/:user/avatar.png",
|
source: "/:user/avatar.png",
|
||||||
destination: "/api/user/avatar?username=:user",
|
destination: "/api/user/avatar?username=:user",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
source: "/team/:teamname/avatar.png",
|
||||||
|
destination: "/api/user/avatar?teamname=:teamname",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
async redirects() {
|
async redirects() {
|
||||||
|
|
|
@ -1,31 +1,60 @@
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
|
||||||
|
import { getPlaceholderAvatar } from "@lib/getPlaceholderAvatar";
|
||||||
import prisma from "@lib/prisma";
|
import prisma from "@lib/prisma";
|
||||||
import { defaultAvatarSrc } from "@lib/profile";
|
import { defaultAvatarSrc } from "@lib/profile";
|
||||||
|
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
// const username = req.url?.substring(1, req.url.lastIndexOf("/"));
|
// const username = req.url?.substring(1, req.url.lastIndexOf("/"));
|
||||||
const username = req.query.username as string;
|
const username = req.query.username as string;
|
||||||
const user = await prisma.user.findUnique({
|
const teamname = req.query.teamname as string;
|
||||||
where: {
|
let identity;
|
||||||
username: username,
|
if (username) {
|
||||||
},
|
const user = await prisma.user.findUnique({
|
||||||
select: {
|
where: {
|
||||||
avatar: true,
|
username: username,
|
||||||
email: true,
|
},
|
||||||
},
|
select: {
|
||||||
});
|
avatar: true,
|
||||||
|
email: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
identity = {
|
||||||
|
name: username,
|
||||||
|
email: user?.email,
|
||||||
|
avatar: user?.avatar,
|
||||||
|
};
|
||||||
|
} else if (teamname) {
|
||||||
|
const team = await prisma.team.findUnique({
|
||||||
|
where: {
|
||||||
|
slug: teamname,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
logo: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
identity = {
|
||||||
|
name: teamname,
|
||||||
|
shouldDefaultBeNameBased: true,
|
||||||
|
avatar: team?.logo,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const emailMd5 = crypto
|
const emailMd5 = crypto
|
||||||
.createHash("md5")
|
.createHash("md5")
|
||||||
.update((user?.email as string) || "guest@example.com")
|
.update((identity?.email as string) || "guest@example.com")
|
||||||
.digest("hex");
|
.digest("hex");
|
||||||
const img = user?.avatar;
|
const img = identity?.avatar;
|
||||||
if (!img) {
|
if (!img) {
|
||||||
|
let defaultSrc = defaultAvatarSrc({ md5: emailMd5 });
|
||||||
|
if (identity?.shouldDefaultBeNameBased) {
|
||||||
|
defaultSrc = getPlaceholderAvatar(null, identity.name);
|
||||||
|
}
|
||||||
res.writeHead(302, {
|
res.writeHead(302, {
|
||||||
Location: defaultAvatarSrc({ md5: emailMd5 }),
|
Location: defaultSrc,
|
||||||
});
|
});
|
||||||
|
|
||||||
res.end();
|
res.end();
|
||||||
} else if (!img.includes("data:image")) {
|
} else if (!img.includes("data:image")) {
|
||||||
res.writeHead(302, {
|
res.writeHead(302, {
|
||||||
|
|
|
@ -18,6 +18,7 @@ import Link from "next/link";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import React, { Fragment, useEffect, useState } from "react";
|
import React, { Fragment, useEffect, useState } from "react";
|
||||||
|
|
||||||
|
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||||
import showToast from "@calcom/lib/notification";
|
import showToast from "@calcom/lib/notification";
|
||||||
import { Button } from "@calcom/ui";
|
import { Button } from "@calcom/ui";
|
||||||
|
@ -452,45 +453,48 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const EventTypeListHeading = ({ profile, membershipCount }: EventTypeListHeadingProps): JSX.Element => (
|
const EventTypeListHeading = ({ profile, membershipCount }: EventTypeListHeadingProps): JSX.Element => {
|
||||||
<div className="mb-4 flex">
|
console.log(profile.slug);
|
||||||
<Link href="/settings/teams">
|
return (
|
||||||
<a>
|
<div className="mb-4 flex">
|
||||||
<Avatar
|
|
||||||
alt={profile?.name || ""}
|
|
||||||
imageSrc={profile?.image || undefined}
|
|
||||||
size={8}
|
|
||||||
className="mt-1 inline ltr:mr-2 rtl:ml-2"
|
|
||||||
/>
|
|
||||||
</a>
|
|
||||||
</Link>
|
|
||||||
<div>
|
|
||||||
<Link href="/settings/teams">
|
<Link href="/settings/teams">
|
||||||
<a className="font-bold">{profile?.name || ""}</a>
|
<a>
|
||||||
|
<Avatar
|
||||||
|
alt={profile?.name || ""}
|
||||||
|
imageSrc={`${WEBAPP_URL}/${profile.slug}/avatar.png` || undefined}
|
||||||
|
size={8}
|
||||||
|
className="mt-1 inline ltr:mr-2 rtl:ml-2"
|
||||||
|
/>
|
||||||
|
</a>
|
||||||
</Link>
|
</Link>
|
||||||
{membershipCount && (
|
<div>
|
||||||
<span className="relative -top-px text-xs text-neutral-500 ltr:ml-2 rtl:mr-2">
|
<Link href="/settings/teams">
|
||||||
<Link href="/settings/teams">
|
<a className="font-bold">{profile?.name || ""}</a>
|
||||||
<a>
|
|
||||||
<Badge variant="gray">
|
|
||||||
<UsersIcon className="mr-1 -mt-px inline h-3 w-3" />
|
|
||||||
{membershipCount}
|
|
||||||
</Badge>
|
|
||||||
</a>
|
|
||||||
</Link>
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
{profile?.slug && (
|
|
||||||
<Link href={`${process.env.NEXT_PUBLIC_WEBSITE_URL}/${profile.slug}`}>
|
|
||||||
<a className="block text-xs text-neutral-500">{`${process.env.NEXT_PUBLIC_WEBSITE_URL?.replace(
|
|
||||||
"https://",
|
|
||||||
""
|
|
||||||
)}/${profile.slug}`}</a>
|
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
{membershipCount && (
|
||||||
|
<span className="relative -top-px text-xs text-neutral-500 ltr:ml-2 rtl:mr-2">
|
||||||
|
<Link href="/settings/teams">
|
||||||
|
<a>
|
||||||
|
<Badge variant="gray">
|
||||||
|
<UsersIcon className="mr-1 -mt-px inline h-3 w-3" />
|
||||||
|
{membershipCount}
|
||||||
|
</Badge>
|
||||||
|
</a>
|
||||||
|
</Link>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{profile?.slug && (
|
||||||
|
<Link href={`${process.env.NEXT_PUBLIC_WEBSITE_URL}/${profile.slug}`}>
|
||||||
|
<a className="block text-xs text-neutral-500">{`${process.env.NEXT_PUBLIC_WEBSITE_URL?.replace(
|
||||||
|
"https://",
|
||||||
|
""
|
||||||
|
)}/${profile.slug}`}</a>
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
);
|
||||||
);
|
};
|
||||||
|
|
||||||
const CreateFirstEventTypeView = ({ canAddEvents, profiles }: CreateEventTypeProps) => {
|
const CreateFirstEventTypeView = ({ canAddEvents, profiles }: CreateEventTypeProps) => {
|
||||||
const { t } = useLocale();
|
const { t } = useLocale();
|
||||||
|
|
|
@ -137,7 +137,6 @@ const loggedInViewerRouter = createProtectedRouter()
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
username: true,
|
username: true,
|
||||||
avatar: true,
|
|
||||||
name: true,
|
name: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -154,7 +153,6 @@ const loggedInViewerRouter = createProtectedRouter()
|
||||||
startTime: true,
|
startTime: true,
|
||||||
endTime: true,
|
endTime: true,
|
||||||
bufferTime: true,
|
bufferTime: true,
|
||||||
avatar: true,
|
|
||||||
plan: true,
|
plan: true,
|
||||||
teams: {
|
teams: {
|
||||||
where: {
|
where: {
|
||||||
|
@ -230,7 +228,6 @@ const loggedInViewerRouter = createProtectedRouter()
|
||||||
profile: {
|
profile: {
|
||||||
slug: typeof user["username"];
|
slug: typeof user["username"];
|
||||||
name: typeof user["name"];
|
name: typeof user["name"];
|
||||||
image: typeof user["avatar"];
|
|
||||||
};
|
};
|
||||||
metadata: {
|
metadata: {
|
||||||
membershipCount: number;
|
membershipCount: number;
|
||||||
|
@ -255,7 +252,6 @@ const loggedInViewerRouter = createProtectedRouter()
|
||||||
profile: {
|
profile: {
|
||||||
slug: user.username,
|
slug: user.username,
|
||||||
name: user.name,
|
name: user.name,
|
||||||
image: user.avatar,
|
|
||||||
},
|
},
|
||||||
eventTypes: _.orderBy(mergedEventTypes, ["position", "id"], ["desc", "asc"]),
|
eventTypes: _.orderBy(mergedEventTypes, ["position", "id"], ["desc", "asc"]),
|
||||||
metadata: {
|
metadata: {
|
||||||
|
|
Loading…
Reference in a new issue