The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix create link issue + tags-section bug
Steven Teyca37394db63f
diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.tsindex 30d08a306d..792481ad89 100644--- a/apps/web/lib/api/links.ts+++ b/apps/web/lib/api/links.ts@@ -282,7 +282,6 @@ export async function processLink({ios,android,geo,- projectId,} = payload;// url checks@@ -430,43 +429,7 @@ export async function processLink({}}- const combinedTagIds = combineTagIds(payload);- // tag checks- if (combinedTagIds.length > 0) {- if (!projectId) {- return {- link: payload,- error: "Missing projectId.",- status: 400,- };- }- // check if there are any tags that don't belong to the project- const projectTags = await prisma.tag.findMany({- where: {- projectId,- id: {- in: combinedTagIds,- },- },- select: {- id: true,- },- });- if (projectTags.length !== combinedTagIds.length) {- const invalidTagIds = combinedTagIds.filter(- (tagId) => !projectTags.find((tag) => tag.id === tagId),- );- return {- link: payload,- error: `One or more tags do not belong to the project: ${invalidTagIds.join(- ", ",- )}.`,- status: 422,- };- }- }-- // remove shortLink & qrCode attributes from payload since it's a polyfill+ // remove polyfill attributes from payloaddelete payload["shortLink"];delete payload["qrCode"];@@ -489,32 +452,33 @@ export async function processLink({}export async function addLink(link: LinkWithTagIdsProps) {- const {- domain,- key,- url,- expiresAt,- title,- description,- image,- proxy,- geo,- tagId,- tagIds,- } = link;+ let { domain, key, url, expiresAt, title, description, image, proxy, geo } =+ link;const uploadedImage = image && image.startsWith("data:image") ? true : false;- const combinedTagIds = combineTagIds({ tagId, tagIds });-const exists = await checkIfKeyExists(domain, key);if (exists) return null;+ const combinedTagIds = combineTagIds(link);+const { utm_source, utm_medium, utm_campaign, utm_term, utm_content } =getParamsFromURL(url);- let response = await prisma.link.create({+ if (proxy && image) {+ const { secure_url } = await cloudinary.v2.uploader.upload(image, {+ public_id: key,+ folder: domain,+ overwrite: true,+ invalidate: true,+ });+ image = secure_url;+ }++ const { tagId, tagIds, ...rest } = link;++ const response = await prisma.link.create({data: {- ...link,+ ...rest,key,title: truncate(title, 120),description: truncate(description, 240),@@ -536,22 +500,6 @@ export async function addLink(link: LinkWithTagIdsProps) {},});- if (proxy && image) {- const { secure_url } = await cloudinary.v2.uploader.upload(image, {- public_id: key,- folder: domain,- overwrite: true,- invalidate: true,- });- response = await prisma.link.update({- where: {- id: response.id,- },- data: {- image: secure_url,- },- });- }const shortLink = linkConstructor({domain: response.domain,key: response.key,@@ -692,14 +640,13 @@ export async function editLink({const { utm_source, utm_medium, utm_campaign, utm_term, utm_content } =getParamsFromURL(url);- const combinedTagIds = combineTagIds(updatedLink);-// exclude fields that should not be updatedconst {id: _,clicks,lastClicked,updatedAt,+ tagId,tagIds,...rest} = updatedLink;@@ -725,10 +672,10 @@ export async function editLink({tags: {deleteMany: {tagId: {- notIn: combinedTagIds,+ notIn: tagIds,},},- connectOrCreate: combinedTagIds.map((tagId) => ({+ connectOrCreate: tagIds.map((tagId) => ({where: { linkId_tagId: { linkId: id, tagId } },create: { tagId },})),diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.tsindex 3152f5b8c8..4c5074f3cc 100644--- a/apps/web/lib/types.ts+++ b/apps/web/lib/types.ts@@ -1,5 +1,5 @@import { DirectorySyncProviders } from "@boxyhq/saml-jackson";-import { Link, Tag } from "@prisma/client";+import { Link } from "@prisma/client";export type LinkProps = Link;@@ -8,7 +8,7 @@ export interface LinkWithTagsProps extends LinkProps {}export interface LinkWithTagIdsProps extends LinkProps {- tagIds?: string[];+ tagIds: string[];}export interface SimpleLinkProps {diff --git a/apps/web/package.json b/apps/web/package.jsonindex caa214c215..a2c151bbf4 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -17,7 +17,7 @@"@dub/utils": "workspace:*","@next-auth/prisma-adapter": "^1.0.5","@planetscale/database": "^1.7.0",- "@prisma/client": "^5.2.0",+ "@prisma/client": "^5.9.1","@react-email/components": "^0.0.14","@react-email/render": "^0.0.12","@sindresorhus/slugify": "^2.2.1",@@ -60,7 +60,7 @@"nodemailer": "^6.9.3","npm": "^9.1.2","openapi-types": "^12.1.3",- "prisma": "^5.2.0",+ "prisma": "^5.9.1","punycode": "^2.3.0","react": "^18.2.0","react-colorful": "^5.6.1",diff --git a/apps/web/ui/modals/add-edit-link-modal/tags-section.tsx b/apps/web/ui/modals/add-edit-link-modal/tags-section.tsxindex 5018a99afc..4b6512a56c 100644--- a/apps/web/ui/modals/add-edit-link-modal/tags-section.tsx+++ b/apps/web/ui/modals/add-edit-link-modal/tags-section.tsx@@ -106,7 +106,7 @@ export default function TagsSection({return (<div className="border-b border-gray-200 pb-5"><Command ref={commandRef} className="relative" loop>- <div className="group mt-1 rounded-md border border-gray-300 bg-white px-1 py-2 focus-within:border-gray-500 focus-within:ring-1 focus-within:ring-gray-500">+ <div className="group rounded-md border border-gray-300 bg-white p-1 focus-within:border-gray-500 focus-within:ring-1 focus-within:ring-gray-500"><div className="absolute inset-y-0 left-0 flex items-center justify-center pl-3 text-gray-400">{creatingTag ? (<LoadingCircle />@@ -124,7 +124,7 @@ export default function TagsSection({</Tooltip>)}</div>- <div className="flex flex-wrap gap-1.5 px-8">+ <div className="flex flex-wrap space-x-1.5 px-8">{tags.map((tag) => (<TagBadge key={tag.id} {...tag} />))}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex a5093955a6..6db694aa4a 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -48,13 +48,13 @@ importers:version: link:../../packages/utils'@next-auth/prisma-adapter':specifier: ^1.0.5- version: 1.0.5(@prisma/[email protected])([email protected])+ version: 1.0.5(@prisma/[email protected])([email protected])'@planetscale/database':specifier: ^1.7.0version: 1.7.0'@prisma/client':- specifier: ^5.2.0- version: 5.2.0([email protected])+ specifier: ^5.9.1+ version: 5.9.1([email protected])'@react-email/components':specifier: ^0.0.14version: 0.0.14(@types/[email protected])([email protected])@@ -182,8 +182,8 @@ importers:specifier: ^12.1.3version: 12.1.3prisma:- specifier: ^5.2.0- version: 5.2.0+ specifier: ^5.9.1+ version: 5.9.1punycode:specifier: ^2.3.0version: 2.3.0@@ -3421,13 +3421,13 @@ packages:sparse-bitfield: 3.0.3dev: falseresolution: {integrity: sha512-VqMS11IxPXrPGXw6Oul6jcyS/n8GLOWzRMrPr3EMdtD6eOalM6zz05j08PcNiis8QzkfuYnCv49OvufTuaEwYQ==}peerDependencies:'@prisma/client': '>=2.26.0 || >=3'next-auth: ^4dependencies:- '@prisma/client': 5.2.0([email protected])+ '@prisma/client': 5.9.1([email protected])dev: false@@ -3998,8 +3998,8 @@ packages:engines: {node: '>=16'}dev: false- /@prisma/[email protected]([email protected]):- resolution: {integrity: sha512-AiTjJwR4J5Rh6Z/9ZKrBBLel3/5DzUNntMohOy7yObVnVoTNVFi2kvpLZlFuKO50d7yDspOtW6XBpiAd0BVXbQ==}+ /@prisma/[email protected]([email protected]):+ resolution: {integrity: sha512-caSOnG4kxcSkhqC/2ShV7rEoWwd3XrftokxJqOCMVvia4NYV/TPtJlS9C2os3Igxw/Qyxumj9GBQzcStzECvtQ==}engines: {node: '>=16.13'}requiresBuild: truepeerDependencies:@@ -4008,17 +4008,39 @@ packages:prisma:optional: truedependencies:- '@prisma/engines-version': 5.2.0-25.2804dc98259d2ea960602aca6b8e7fdc03c1758f- prisma: 5.2.0+ prisma: 5.9.1dev: false- /@prisma/engines-version@5.2.0-25.2804dc98259d2ea960602aca6b8e7fdc03c1758f:- resolution: {integrity: sha512-jsnKT5JIDIE01lAeCj2ghY9IwxkedhKNvxQeoyLs6dr4ZXynetD0vTy7u6wMJt8vVPv8I5DPy/I4CFaoXAgbtg==}+ /@prisma/[email protected]:+ resolution: {integrity: sha512-yAHFSFCg8KVoL0oRUno3m60GAjsUKYUDkQ+9BA2X2JfVR3kRVSJFc/GpQ2fSORi4pSHZR9orfM4UC9OVXIFFTA==}dev: false- /@prisma/[email protected]:- resolution: {integrity: sha512-dT7FOLUCdZmq+AunLqB1Iz+ZH/IIS1Fz2THmKZQ6aFONrQD/BQ5ecJ7g2wGS2OgyUFf4OaLam6/bxmgdOBDqig==}+ /@prisma/engines-version@5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64:+ resolution: {integrity: sha512-HFl7275yF0FWbdcNvcSRbbu9JCBSLMcurYwvWc8WGDnpu7APxQo2ONtZrUggU3WxLxUJ2uBX+0GOFIcJeVeOOQ==}+ dev: false++ /@prisma/[email protected]:+ resolution: {integrity: sha512-gkdXmjxQ5jktxWNdDA5aZZ6R8rH74JkoKq6LD5mACSvxd2vbqWeWIOV0Py5wFC8vofOYShbt6XUeCIUmrOzOnQ==}requiresBuild: true+ dependencies:+ '@prisma/debug': 5.9.1+ '@prisma/engines-version': 5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64+ '@prisma/fetch-engine': 5.9.1+ '@prisma/get-platform': 5.9.1+ dev: false++ /@prisma/[email protected]:+ resolution: {integrity: sha512-l0goQOMcNVOJs1kAcwqpKq3ylvkD9F04Ioe1oJoCqmz05mw22bNAKKGWuDd3zTUoUZr97va0c/UfLNru+PDmNA==}+ dependencies:+ '@prisma/debug': 5.9.1+ '@prisma/engines-version': 5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64+ '@prisma/get-platform': 5.9.1+ dev: false++ /@prisma/[email protected]:+ resolution: {integrity: sha512-6OQsNxTyhvG+T2Ksr8FPFpuPeL4r9u0JF0OZHUBI/Uy9SS43sPyAIutt4ZEAyqWQt104ERh70EZedkHZKsnNbg==}+ dependencies:+ '@prisma/debug': 5.9.1dev: false/@protobufjs/[email protected]:@@ -12952,13 +12974,13 @@ packages:react: 18.2.0dev: false- resolution: {integrity: sha512-FfFlpjVCkZwrqxDnP4smlNYSH1so+CbfjgdpioFzGGqlQAEm6VHAYSzV7jJgC3ebtY9dNOhDMS2+4/1DDSM7bQ==}+ resolution: {integrity: sha512-Hy/8KJZz0ELtkw4FnG9MS9rNWlXcJhf98Z2QMqi0QiVMoS8PzsBkpla0/Y5hTlob8F3HeECYphBjqmBxrluUrQ==}engines: {node: '>=16.13'}hasBin: truerequiresBuild: truedependencies:- '@prisma/engines': 5.2.0+ '@prisma/engines': 5.9.1dev: false