Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/sujjeee/dub into pr/1305
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey committed Oct 4, 2024
2 parents 55dd1fb bb5b47e commit fa4af24
Show file tree
Hide file tree
Showing 28 changed files with 206 additions and 423 deletions.
2 changes: 1 addition & 1 deletion apps/web/app/api/events/export/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 30,7 @@ const columnAccessors = {
event: (r: LeadEvent | SaleEvent) => r.eventName,
link: (r: Row) => r.domain (r.key === "_root" ? "" : `/${r.key}`),
country: (r: Row) =>
r.country ? COUNTRIES[r.country] ?? r.country : r.country,
r.country ? (COUNTRIES[r.country] ?? r.country) : r.country,
customer: (r: LeadEvent | SaleEvent) =>
r.customer.name (r.customer.email ? ` <${r.customer.email}>` : ""),
invoiceId: (r: SaleEvent) => r.sale.invoiceId,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/ui/analytics/analytics-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 105,7 @@ export default function AnalyticsProvider({

// Only set interval if start and end are not provided
const interval =
start || end ? undefined : searchParams?.get("interval") ?? "24h";
start || end ? undefined : (searchParams?.get("interval") ?? "24h");

const selectedTab: EventType = useMemo(() => {
if (!!adminPage && !!demoPage && !conversionEnabled) return "clicks";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/ui/analytics/events/events-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 520,7 @@ export default function EventsTable() {
columns,
pagination,
onPaginationChange: setPagination,
rowCount: needsHigherPlan ? 0 : totalEvents?.[tab] ?? 0,
rowCount: needsHigherPlan ? 0 : (totalEvents?.[tab] ?? 0),
columnVisibility: columnVisibility[tab],
onColumnVisibilityChange: (args) => setColumnVisibility(tab, args),
sortableColumns: ["timestamp"],
Expand Down
2 changes: 1 addition & 1 deletion apps/web/ui/analytics/events/events-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 110,7 @@ export default function EventsTabs() {
>
{event === "sales"
? (totalEvents?.saleAmount ?? 0) / 100
: totalEvents?.[event] ?? 0}
: (totalEvents?.[event] ?? 0)}
</CountingNumbers>
) : (
<div className="h-8 w-12 animate-pulse rounded-md bg-gray-200" />
Expand Down
2 changes: 1 addition & 1 deletion apps/web/ui/analytics/toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 643,7 @@ export default function Toggle({
}
: undefined
}
presetId={!start || !end ? interval ?? "24h" : undefined}
presetId={!start || !end ? (interval ?? "24h") : undefined}
onChange={(range, preset) => {
if (preset) {
queryParams({
Expand Down
2 changes: 1 addition & 1 deletion apps/web/ui/charts/x-axis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 34,7 @@ export default function XAxis({
const { tooltipData } = useChartTooltipContext();

const tickValues = useMemo(() => {
const maxTicks = maxTicksProp ?? width < 450 ? 4 : width < 600 ? 6 : 8;
const maxTicks = (maxTicksProp ?? width < 450) ? 4 : width < 600 ? 6 : 8;

const tickInterval =
getFactors(data.length).find((f) => (data.length 1) / f <= maxTicks) ??
Expand Down
2 changes: 1 addition & 1 deletion apps/web/ui/charts/y-axis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 58,7 @@ export default function YAxis({
const tickValues = useMemo(() => {
if (tickValuesProp) return tickValuesProp;

const numTicks = numTicksProp ?? height < 350 ? 3 : 4;
const numTicks = (numTicksProp ?? height < 350) ? 3 : 4;

return yScale.ticks(numTicks).filter((value) =>
// Both of these reduce the number of ticks farther below numTicks, but this should only affect small ranges
Expand Down
4 changes: 2 additions & 2 deletions apps/web/ui/domains/domain-configuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 69,7 @@ export default function DomainConfiguration({
records={[
{
type: recordType,
name: recordType === "A" ? "@" : subdomain ?? "www",
name: recordType === "A" ? "@" : (subdomain ?? "www"),
value: recordType === "A" ? `76.76.21.21` : `cname.dub.co`,
ttl: "86400",
},
Expand Down Expand Up @@ -112,7 112,7 @@ export default function DomainConfiguration({
records={[
{
type: recordType,
name: recordType === "A" ? "@" : subdomain ?? "www",
name: recordType === "A" ? "@" : (subdomain ?? "www"),
value: recordType === "A" ? `76.76.21.21` : `cname.dub.co`,
ttl: "86400",
},
Expand Down
2 changes: 1 addition & 1 deletion apps/web/ui/layout/user-survey/survey-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 72,7 @@ export default function SurveyForm({
onSubmit={(e) => {
e.preventDefault();
if (source)
onSubmit(source === "other" ? otherSource ?? source : source);
onSubmit(source === "other" ? (otherSource ?? source) : source);
}}
>
<RadioGroup
Expand Down
2 changes: 1 addition & 1 deletion apps/web/ui/modals/export-links-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 163,7 @@ function ExportLinksModal({
}
presetId={
!field.value.from || !field.value.to
? field.value.interval ?? "all"
? (field.value.interval ?? "all")
: undefined
}
onChange={(dateRange, preset) => {
Expand Down
34 changes: 15 additions & 19 deletions apps/web/ui/modals/link-builder/draft-controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 81,21 @@ export const DraftControls = forwardRef<
return () => unsubscribe();
}, [watch, isDirty]);

useImperativeHandle(
ref,
() => {
return {
onSubmitSuccessful() {
// Remove the current draft when it's submitted
removeDraft(sessionId);
},
onClose() {
// Save draft instantly when the link builder is closed
const [url, key] = getValues(["url", "key"]);
if ((url || key) && isDirty) {
saveDraft(sessionId, getValues());
}
},
};
},
[sessionId, isDirty],
);
useImperativeHandle(ref, () => {
return {
onSubmitSuccessful() {
// Remove the current draft when it's submitted
removeDraft(sessionId);
},
onClose() {
// Save draft instantly when the link builder is closed
const [url, key] = getValues(["url", "key"]);
if ((url || key) && isDirty) {
saveDraft(sessionId, getValues());
}
},
};
}, [sessionId, isDirty]);

return (isDirty && hasSaved) || drafts.length > 0 ? (
<Popover
Expand Down
4 changes: 2 additions & 2 deletions apps/web/ui/modals/welcome-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 51,9 @@ function WelcomeModal({
}, [searchParams, planId]);

const plan = planId
? PLANS.find(
? (PLANS.find(
(p) => p.name.toLowerCase() === planId.replace(" ", " ").toLowerCase(),
) ?? PRO_PLAN
) ?? PRO_PLAN)
: undefined;

return (
Expand Down
31 changes: 31 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 1,31 @@
# `dub-cli`

a cli for easily shortening URLs.

## Running Locally

To install the package and then,

1. Navigate to the cli folder

```bash
cd packages/cli
```

2. Start the development server

```bash
pnpm dev
```

3. Run commands

```bash
pnpm start [command]
```

4. See all available commands and options

```bash
pnpm start help
```
Original file line number Diff line number Diff line change
@@ -1,8 1,13 @@
import type { GetDomain } from "@/types";
import { getConfig } from "@/utils/get-config";
import type { Domain } from "@/types";
import { getConfig } from "@/utils/config";
import { parseApiResponse } from "@/utils/parser";
import fetch from "node-fetch";

interface UpdateDomainProps {
oldSlug: string;
newSlug: string;
}

export async function getDomains() {
const config = await getConfig();

Expand All @@ -14,8 19,19 @@ export async function getDomains() {
},
};

const response = await fetch("https://api.dub.co/domains", options);
return await parseApiResponse<GetDomain[]>(response);
const [domainsResponse, defaultDomainsResponse] = await Promise.all([
fetch("https://api.dub.co/domains", options),
fetch("https://api.dub.co/domains/default", options),
]);

const [domains, defaultDomains] = await Promise.all([
parseApiResponse<Domain[]>(domainsResponse),
parseApiResponse<string[]>(defaultDomainsResponse),
]);

const allSlugs = [...domains.map((domain) => domain.slug), ...defaultDomains];

return Array.from(new Set(allSlugs));
}

export async function createDomain(slug: string) {
Expand All @@ -33,12 49,8 @@ export async function createDomain(slug: string) {
};

const response = await fetch("https://api.dub.co/domains", options);
return await parseApiResponse<GetDomain[]>(response);
}

interface UpdateDomainProps {
oldSlug: string;
newSlug: string;
return await parseApiResponse<Domain[]>(response);
}

export async function updateDomain({ newSlug, oldSlug }: UpdateDomainProps) {
Expand All @@ -60,9 72,7 @@ export async function updateDomain({ newSlug, oldSlug }: UpdateDomainProps) {
options,
);

const parsedResponse = await parseApiResponse<GetDomain[]>(response);

return parsedResponse;
return await parseApiResponse<Domain[]>(response);
}

export async function deleteDomain(slug: string) {
Expand All @@ -76,5 86,6 @@ export async function deleteDomain(slug: string) {
};

const response = await fetch(`https://api.dub.co/domains/${slug}`, options);
return await parseApiResponse<GetDomain["id"]>(response);

return await parseApiResponse<Domain["id"]>(response);
}
Original file line number Diff line number Diff line change
@@ -1,5 1,5 @@
import type { CreateLinkProps, GetLink } from "@/types";
import { getConfig } from "@/utils/get-config";
import type { CreateLinkProps, Link } from "@/types";
import { getConfig } from "@/utils/config";
import { parseApiResponse } from "@/utils/parser";
import fetch from "node-fetch";

Expand All @@ -20,7 20,8 @@ export async function createLink({ url, key }: CreateLinkProps) {
};

const response = await fetch("https://api.dub.co/links", options);
return await parseApiResponse<GetLink>(response);

return await parseApiResponse<Link>(response);
}

export async function getLinks() {
Expand All @@ -35,12 36,6 @@ export async function getLinks() {
};

const response = await fetch("https://api.dub.co/links", options);
const parsedData = await parseApiResponse<GetLink[]>(response);

const links = parsedData.map((link) => ({
url: `https://${link.domain}/${link.key}`,
clicks: link.clicks,
}));

return links;
return await parseApiResponse<Link[]>(response);
}
4 changes: 2 additions & 2 deletions packages/cli/src/commands/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
import { getConfig } from "@/utils/get-config";
import { getConfig } from "@/utils/config";
import { handleError } from "@/utils/handle-error";
import { logger } from "@/utils/logger";
import { Command } from "commander";
Expand All @@ -7,7 7,7 @@ import ora from "ora";

export const config = new Command()
.name("config")
.description("see your configured workspace credentails")
.description("see your configured workspace credentials")
.action(async () => {
const spinner = ora("Getting config file").start();

Expand Down
Loading

0 comments on commit fa4af24

Please sign in to comment.