Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add landerPublishedAt

Steven Teybcbf4feef644
diff --git a/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/apply/page.tsx b/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/apply/page.tsx
index e0ccc39233..4d1769d5ec 100644
--- a/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/apply/page.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/apply/page.tsx
@@ -15,7 +15,7 @@ export default async function ApplicationPage({
include: ["rewards", "defaultDiscount"],
});
- if (!program || !program.defaultRewardId) {
+ if (!program) {
notFound();
}
diff --git a/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/layout.tsx b/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/layout.tsx
index 5b1064b0ec..3b1a51eed2 100644
--- a/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/layout.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/layout.tsx
@@ -2,7 +2,6 @@ import { getProgram } from "@/lib/fetchers/get-program";
import { getReward } from "@/lib/fetchers/get-reward";
import { formatRewardDescription } from "@/ui/partners/format-reward-description";
import { prisma } from "@dub/prisma";
-import { Prisma } from "@dub/prisma/client";
import { Wordmark } from "@dub/ui";
import { APP_DOMAIN } from "@dub/utils";
import { constructMetadata } from "@dub/utils/src/functions";
@@ -34,11 +33,6 @@ export async function generateMetadata({
export async function generateStaticParams() {
const programs = await prisma.program.findMany({
- where: {
- landerData: {
- not: Prisma.JsonNull,
- },
- },
select: {
slug: true,
},
diff --git a/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/page.tsx b/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/page.tsx
index 3ff1b02bb8..57cde61929 100644
--- a/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/page.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(apply)/[programSlug]/page.tsx
@@ -18,7 +18,7 @@ export default async function ApplyPage({
include: ["rewards", "defaultDiscount"],
});
- if (!program || !program.landerData || !program.defaultRewardId) {
+ if (!program || !program.landerData || !program.landerPublishedAt) {
notFound();
}
diff --git a/apps/web/app/sitemap.ts b/apps/web/app/sitemap.ts
index e53faacf51..7d9e806dcb 100644
--- a/apps/web/app/sitemap.ts
+++ b/apps/web/app/sitemap.ts
@@ -19,6 +19,9 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
landerData: {
not: Prisma.JsonNull,
},
+ landerPublishedAt: {
+ not: null,
+ },
},
});
diff --git a/apps/web/lib/actions/partners/update-program.ts b/apps/web/lib/actions/partners/update-program.ts
index fc9a68069a..311e9e32ec 100644
--- a/apps/web/lib/actions/partners/update-program.ts
+++ b/apps/web/lib/actions/partners/update-program.ts
@@ -82,6 +82,7 @@ export const updateProgramAction = authActionClient
wordmark: wordmarkUrl ?? undefined,
brandColor,
landerData: landerData === null ? Prisma.JsonNull : landerData,
+ landerPublishedAt: landerData ? new Date() : undefined,
domain,
url,
linkStructure,
diff --git a/apps/web/lib/zod/schemas/programs.ts b/apps/web/lib/zod/schemas/programs.ts
index ec6663c7ce..db1bae0787 100644
--- a/apps/web/lib/zod/schemas/programs.ts
+++ b/apps/web/lib/zod/schemas/programs.ts
@@ -46,6 +46,7 @@ export const ProgramSchema = z.object({
export const ProgramWithLanderDataSchema = ProgramSchema.extend({
landerData: programLanderSchema.nullish(),
+ landerPublishedAt: z.date().nullish(),
});
export const updateProgramSchema = z.object({
diff --git a/apps/web/scripts/framer/process-lead-events.ts b/apps/web/scripts/framer/process-lead-events.ts
new file mode 100644
index 0000000000..a351797af3
--- /dev/null
+++ b/apps/web/scripts/framer/process-lead-events.ts
@@ -0,0 +1,108 @@
+import { prisma } from "@dub/prisma";
+import { chunk } from "@dub/utils";
+import "dotenv-flow/config";
+import * as fs from "fs";
+import * as Papa from "papaparse";
+
+type RawDataProps = {
+ event_name: string;
+ timestamp: string;
+ customer_id: string;
+ link_id: string;
+};
+
+type ProcessedDataProps = {
+ via: string;
+ externalId: string;
+ eventName: string;
+ creationDate: Date;
+};
+
+let rawData: RawDataProps[] = [];
+let customerIdsSet = new Set<string>();
+let linkIdsSet = new Set<string>();
+
+const BATCH = 7;
+const FRAMER_WORKSPACE_ID = "xxx";
+
+async function main() {
+ Papa.parse(
+ fs.createReadStream(`get_framer_lead_events_${BATCH}.csv`, "utf-8"),
+ {
+ header: true,
+ skipEmptyLines: true,
+ step: (result: { data: RawDataProps }) => {
+ const { customer_id, link_id } = result.data;
+ rawData.push(result.data);
+ linkIdsSet.add(link_id);
+ customerIdsSet.add(customer_id);
+ },
+ complete: async () => {
+ const linkIdsArray = Array.from(linkIdsSet);
+ const customerIdsArray = Array.from(customerIdsSet);
+
+ console.log(
+ `Found ${linkIdsArray.length} links and ${customerIdsArray.length} customers`,
+ );
+
+ const links = await prisma.link.findMany({
+ where: {
+ id: {
+ in: linkIdsArray,
+ },
+ projectId: FRAMER_WORKSPACE_ID,
+ },
+ select: {
+ id: true,
+ key: true,
+ },
+ });
+
+ let customers: { id: string; externalId: string | null }[] = [];
+ const customerIdChunks = chunk(customerIdsArray, 1000);
+ for (const customerIdChunk of customerIdChunks) {
+ const data = await prisma.customer.findMany({
+ where: {
+ id: {
+ in: customerIdChunk,
+ },
+ projectId: FRAMER_WORKSPACE_ID,
+ },
+ select: {
+ id: true,
+ externalId: true,
+ },
+ });
+ customers.push(...data);
+ }
+
+ console.log(`Found ${customers.length} customers`);
+
+ const processedData = rawData
+ .map((data) => {
+ const link = links.find((link) => link.id === data.link_id);
+ const customer = customers.find(
+ (customer) => customer.id === data.customer_id,
+ );
+ if (!link || !customer || !customer.externalId) {
+ return null;
+ }
+ return {
+ via: link.key,
+ externalId: customer.externalId,
+ eventName: data.event_name,
+ creationDate: new Date(data.timestamp),
+ };
+ })
+ .filter((data) => data !== null) satisfies ProcessedDataProps[];
+
+ fs.writeFileSync(
+ `processed_framer_lead_events_${BATCH}.csv`,
+ Papa.unparse(processedData),
+ );
+ },
+ },
+ );
+}
+
+main();
diff --git a/apps/web/scripts/tinybird/delete-links.ts b/apps/web/scripts/tinybird/delete-links.ts
new file mode 100644
index 0000000000..52ce536ba7
--- /dev/null
+++ b/apps/web/scripts/tinybird/delete-links.ts
@@ -0,0 +1,45 @@
+import "dotenv-flow/config";
+
+// update tinybird sale event
+async function main() {
+ const deleteCondition = "domain = 'xyz'";
+
+ // delete data from tinybird
+ const deleteRes = await Promise.allSettled([
+ deleteData({
+ dataSource: "dub_links_metadata",
+ deleteCondition,
+ }),
+ deleteData({
+ dataSource: "dub_links_metadata_latest",
+ deleteCondition,
+ }),
+ deleteData({
+ dataSource: "dub_regular_links_metadata_latest",
+ deleteCondition,
+ }),
+ ]);
+ console.log(deleteRes);
+}
+
+const deleteData = async ({
+ dataSource,
+ deleteCondition,
+}: {
+ dataSource: string;
+ deleteCondition: string;
+}) => {
+ return fetch(
+ `https://api.us-east.tinybird.co/v0/datasources/${dataSource}/delete`,
+ {
+ method: "POST",
+ headers: {
+ Authorization: `Bearer ${process.env.TINYBIRD_API_KEY}`,
+ "Content-Type": "application/x-www-form-urlencoded",
+ },
+ body: `delete_condition=${deleteCondition}`,
+ },
+ ).then((res) => res.json());
+};
+
+main();
diff --git a/apps/web/ui/partners/design/branding-form.tsx b/apps/web/ui/partners/design/branding-form.tsx
index 53a5f4301a..e02f0db5a4 100644
--- a/apps/web/ui/partners/design/branding-form.tsx
+++ b/apps/web/ui/partners/design/branding-form.tsx
@@ -39,7 +39,11 @@ export function useBrandingFormContext() {
export function BrandingForm() {
const { defaultProgramId } = useWorkspace();
- const { program, mutate, loading } = useProgram<ProgramWithLanderDataProps>(
+ const {
+ program,
+ mutate: mutateProgram,
+ loading,
+ } = useProgram<ProgramWithLanderDataProps>(
{
query: { includeLanderData: true },
},
@@ -63,7 +67,7 @@ export function BrandingForm() {
return (
<BrandingFormInner
program={program}
- mutate={mutate}
+ mutateProgram={mutateProgram}
draft={draft}
setDraft={setDraft}
/>
@@ -90,12 +94,12 @@ const PREVIEW_TABS = [
function BrandingFormInner({
program,
- mutate,
+ mutateProgram,
draft,
setDraft,
}: {
program: ProgramWithLanderDataProps;
- mutate: KeyedMutator<ProgramWithLanderDataProps>;
+ mutateProgram: KeyedMutator<ProgramWithLanderDataProps>;
draft: BrandingFormData | null;
setDraft: (draft: BrandingFormData | null) => void;
}) {
@@ -120,13 +124,17 @@ function BrandingFormInner({
handleSubmit,
reset,
setError,
- formState: { isDirty, isSubmitting },
+ formState: { isDirty, isSubmitting, isSubmitSuccessful },
+ getValues,
} = form;
- const { executeAsync } = useAction(updateProgramAction, {
+ const { executeAsync, isPending } = useAction(updateProgramAction, {
async onSuccess() {
+ await mutateProgram();
toast.success("Program updated successfully.");
- mutate();
+ // Reset form state to clear isSubmitSuccessful
+ const currentValues = getValues();
+ reset(currentValues);
},
onError({ error }) {
console.error(error);
@@ -146,6 +154,12 @@ function BrandingFormInner({
const [isTabPopoverOpen, setIsTabPopoverOpen] = useState(false);
+ // Disable publish button when:
+ // - there are no changes
+ // - the program lander is already published
+ const disablePublishButton =
+ !isDirty && program.landerPublishedAt ? true : false;
+
return (
<form
onSubmit={handleSubmit(async (data) => {
@@ -153,9 +167,6 @@ function BrandingFormInner({
workspaceId: workspaceId!,
...data,
});
-
- // Reset isDirty state
- reset(data);
})}
className="overflow-hidden rounded-lg border border-neutral-200 bg-neutral-100"
>
@@ -227,8 +238,8 @@ function BrandingFormInner({
type="submit"
variant="primary"
text="Publish"
- loading={isSubmitting}
- disabled={!isDirty}
+ loading={isPending || isSubmitting || isSubmitSuccessful}
+ disabled={disablePublishButton}
className="h-8 w-fit px-3"
/>
</div>
diff --git a/packages/prisma/schema/program.prisma b/packages/prisma/schema/program.prisma
index ea3792777a..a563e4bb1b 100644
--- a/packages/prisma/schema/program.prisma
+++ b/packages/prisma/schema/program.prisma
@@ -46,6 +46,7 @@ model Program {
defaultDiscountId String? @unique // default discount for the program
embedData Json? @db.Json
landerData Json? @db.Json
+ landerPublishedAt DateTime?
resources Json? @db.Json
termsUrl String? @db.Text
helpUrl String? @db.Text