The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update test start logic
Tim Wilsoncad3246a5ed6
diff --git a/apps/web/app/api/links/[linkId]/route.ts b/apps/web/app/api/links/[linkId]/route.tsindex f0135c9403..aeea7eae1b 100644--- a/apps/web/app/api/links/[linkId]/route.ts+++ b/apps/web/app/api/links/[linkId]/route.ts@@ -108,6 +108,7 @@ export const PATCH = withWorkspace(? link.expiresAt.toISOString(): link.expiresAt,geo: link.geo as NewLinkProps["geo"],+...body,// for UTM tags, we only pass them to processLink if they have changed from their previous value// or else they will override any changes to the UTM params in the destination URL@@ -172,7 +173,6 @@ export const PATCH = withWorkspace(domain: link.domain,key: link.key,image: link.image,- testsCompleteAt: link.testsCompleteAt,},updatedLink: processedLink,});diff --git a/apps/web/app/api/links/upsert/route.ts b/apps/web/app/api/links/upsert/route.tsindex dfaf4d63e6..098693d9d5 100644--- a/apps/web/app/api/links/upsert/route.ts+++ b/apps/web/app/api/links/upsert/route.ts@@ -146,7 +146,6 @@ export const PUT = withWorkspace(domain: link.domain,key: link.key,image: link.image,- testsCompleteAt: link.testsCompleteAt,},updatedLink: processedLink,});diff --git a/apps/web/app/api/partner-profile/programs/[programId]/links/[linkId]/route.ts b/apps/web/app/api/partner-profile/programs/[programId]/links/[linkId]/route.tsindex 5c4f25f9a4..b94b9c45a8 100644--- a/apps/web/app/api/partner-profile/programs/[programId]/links/[linkId]/route.ts+++ b/apps/web/app/api/partner-profile/programs/[programId]/links/[linkId]/route.ts@@ -100,7 +100,6 @@ export const PATCH = withPartnerProfile(domain: link.domain,key: link.key,image: link.image,- testsCompleteAt: link.testsCompleteAt,},updatedLink: processedLink,});diff --git a/apps/web/app/api/partners/links/upsert/route.ts b/apps/web/app/api/partners/links/upsert/route.tsindex b65c565231..9c5facbfac 100644--- a/apps/web/app/api/partners/links/upsert/route.ts+++ b/apps/web/app/api/partners/links/upsert/route.ts@@ -148,7 +148,6 @@ export const PUT = withWorkspace(domain: link.domain,key: link.key,image: link.image,- testsCompleteAt: link.testsCompleteAt,},updatedLink: processedLink,});diff --git a/apps/web/lib/api/links/complete-tests.ts b/apps/web/lib/api/links/complete-tests.tsindex 24e02ee883..7b34d2afd5 100644--- a/apps/web/lib/api/links/complete-tests.ts+++ b/apps/web/lib/api/links/complete-tests.ts@@ -111,7 +111,6 @@ export async function completeTests(link: Link & { project: Project }) {domain: link.domain,key: link.key,image: link.image,- testsCompleteAt: link.testsCompleteAt,},updatedLink: processedLink,});diff --git a/apps/web/lib/api/links/update-link.ts b/apps/web/lib/api/links/update-link.tsindex b255131c04..f9538a5f9b 100644--- a/apps/web/lib/api/links/update-link.ts+++ b/apps/web/lib/api/links/update-link.ts@@ -28,7 +28,6 @@ export async function updateLink({domain: string;key: string;image?: string | null;- testsCompleteAt?: Date | null;};updatedLink: ProcessedLinkProps &Pick<LinkProps, "id" | "clicks" | "lastClicked" | "updatedAt">;@@ -63,6 +62,7 @@ export async function updateLink({tagNames,webhookIds,tests,+ testsStartedAt,testsCompleteAt,...rest} = updatedLink;@@ -76,15 +76,6 @@ export async function updateLink({key: updatedLink.key,});- // Update testsStartedAt to now if there are tests to be completed, and the old link had no tests or completed tests- const testsStartedAt =- tests &&- testsCompleteAt &&- new Date(testsCompleteAt) > new Date() &&- (!oldLink.testsCompleteAt || new Date(oldLink.testsCompleteAt) < new Date())- ? new Date()- : undefined;-const response = await prisma.link.update({where: {id,@@ -112,7 +103,7 @@ export async function updateLink({tests: tests || Prisma.JsonNull,testsCompleteAt: testsCompleteAt ? new Date(testsCompleteAt) : null,- testsStartedAt,+ testsStartedAt: testsStartedAt ? new Date(testsStartedAt) : null,// Associate tags by tagNames...(tagNames &&diff --git a/apps/web/ui/modals/link-builder/ab-testing/ab-testing-modal.tsx b/apps/web/ui/modals/link-builder/ab-testing/ab-testing-modal.tsxindex 0114272280..b092679506 100644--- a/apps/web/ui/modals/link-builder/ab-testing/ab-testing-modal.tsx+++ b/apps/web/ui/modals/link-builder/ab-testing/ab-testing-modal.tsx@@ -69,19 +69,12 @@ function ABTestingModalInner({}: {setShowABTestingModal: Dispatch<SetStateAction<boolean>>;}) {- const { watch: watchParent, setValue: setValueParent } =- useFormContext<LinkFormData>();+ const { watch: watchParent } = useFormContext<LinkFormData>();const [tests, testsCompleteAt] = watchParent(["tests", "testsCompleteAt"]);return tests && testsCompleteAt && new Date(testsCompleteAt) < new Date() ? (- <ABTestingComplete- setShowABTestingModal={setShowABTestingModal}- onCreateNew={() => {- setValueParent("tests", null, { shouldDirty: true });- setValueParent("testsCompleteAt", null, { shouldDirty: true });- }}- />+ <ABTestingComplete setShowABTestingModal={setShowABTestingModal} />) : (<ABTestingEdit setShowABTestingModal={setShowABTestingModal} />);@@ -135,7 +128,11 @@ function ABTestingEdit({const tests = watch("tests") || [];const testsCompleteAt = watch("testsCompleteAt");- const [idParent, testsParent] = watchParent(["id", "tests"]);+ const [idParent, testsParent, testsStartedAtParent] = watchParent([+ "id",+ "tests",+ "testsStartedAt",+ ]);const addTestUrl = () => {if (!tests.length || tests.length >= MAX_TEST_COUNT) return;@@ -269,6 +266,11 @@ function ABTestingEdit({setValueParent("testsCompleteAt", data.testsCompleteAt, {shouldDirty: true,});+ if (!testsStartedAtParent)+ setValueParent("testsStartedAt", new Date(), {+ shouldDirty: true,+ });+setShowABTestingModal(false);})(e);}}@@ -543,10 +545,8 @@ function ABTestingEdit({function ABTestingComplete({setShowABTestingModal,- onCreateNew,}: {setShowABTestingModal: Dispatch<SetStateAction<boolean>>;- onCreateNew: () => void;}) {const { watch } = useFormContext<LinkFormData>();@@ -590,13 +590,6 @@ function ABTestingComplete({setShowABTestingModal(false);}}/>- <Button- type="submit"- variant="primary"- text="Create new test"- className="h-9 w-fit"- onClick={onCreateNew}- /></div></div></div>