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.

New message flow updates

Tim Wilson8dde32b20f6d
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/messages/layout.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/messages/layout.tsx
index 4852ba8518..ecba115d75 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/messages/layout.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/messages/layout.tsx
@@ -4,6 +4,7 @@ import { useProgramMessages } from "@/lib/swr/use-program-messages";
import { NavButton } from "@/ui/layout/page-content/nav-button";
import { MessagesContext, MessagesPanel } from "@/ui/messages/messages-context";
import { MessagesList } from "@/ui/messages/messages-list";
+import { ProgramSelector } from "@/ui/partners/program-selector";
import { Button, useRouterStuff } from "@dub/ui";
import { Msgs, Pen2 } from "@dub/ui/icons";
import { useParams, useRouter } from "next/navigation";
@@ -45,14 +46,20 @@ export default function MessagesLayout({ children }: { children: ReactNode }) {
Messages
</h1>
</div>
- <Button
- variant="secondary"
- icon={<Pen2 className="size-4" />}
- className="size-8 rounded-lg p-0"
- onClick={() => {
- if (programSlug) router.push(`/messages?new=true`);
- else queryParams({ set: { new: "true" } });
- }}
+ <ProgramSelector
+ selectedProgramSlug={programSlug ?? null}
+ setSelectedProgramSlug={(slug) =>
+ router.push(`/messages/${slug}`)
+ }
+ trigger={
+ <Button
+ type="button"
+ variant="secondary"
+ icon={<Pen2 className="size-4" />}
+ className="size-8 rounded-lg p-0"
+ />
+ }
+ matchTriggerWidth={false}
/>
</div>
<div className="scrollbar-hide grow overflow-y-auto">
@@ -89,16 +96,6 @@ export default function MessagesLayout({ children }: { children: ReactNode }) {
can also start a conversation at any time.
</p>
</div>
-
- <Button
- variant="primary"
- className="mt-6 h-8 w-fit rounded-lg"
- text="Compose message"
- onClick={() => {
- if (programSlug) router.push(`/messages?new=true`);
- else queryParams({ set: { new: "true" } });
- }}
- />
</div>
)}
</div>
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/messages/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/messages/page-client.tsx
index aecd35d3dc..08759c1334 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/messages/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/messages/page-client.tsx
@@ -1,23 +1,11 @@
"use client";
import { useMessagesContext } from "@/ui/messages/messages-context";
-import { ProgramSelector } from "@/ui/partners/program-selector";
-import { useRouterStuff } from "@dub/ui";
import { ChevronLeft, Msgs } from "@dub/ui/icons";
-import { useRouter } from "next/navigation";
-import { useState } from "react";
export function PartnerMessagesPageClient() {
const { setCurrentPanel } = useMessagesContext();
- const router = useRouter();
- const { searchParams, queryParams } = useRouterStuff();
-
- // Short-lived state to display the selected program while the next page loads
- const [selectedProgramSlug, setSelectedProgramSlug] = useState<string | null>(
- null,
- );
-
return (
<div className="flex h-full flex-col">
<div className="border-border-subtle flex h-12 items-center gap-2 border-b px-4 sm:h-16 sm:px-6">
@@ -25,34 +13,17 @@ export function PartnerMessagesPageClient() {
type="button"
onClick={() => {
setCurrentPanel("index");
- queryParams({ del: "new" });
}}
className="@[800px]/page:hidden rounded-lg p-1.5 text-neutral-500 transition-colors hover:bg-neutral-100 hover:text-neutral-900"
>
<ChevronLeft className="size-3.5" />
</button>
- {searchParams.get("new") && (
- <div className="animate-slide-up-fade flex items-center gap-3 [--offset:10px] [animation-duration:1s]">
- <span className="text-content-subtle text-lg font-medium">To</span>
- <div className="min-w-24 sm:w-64">
- <ProgramSelector
- selectedProgramSlug={selectedProgramSlug}
- setSelectedProgramSlug={(slug) => {
- setSelectedProgramSlug(slug);
- router.push(`/messages/${slug}`);
- }}
- />
- </div>
- </div>
- )}
</div>
<div className="flex grow flex-col items-center justify-center gap-4">
<Msgs className="text-content-muted size-10" />
<p className="text-content-muted text-sm font-medium">
- {searchParams.get("new")
- ? "Select a program to message"
- : "Select or compose a message"}
+ Select or compose a message
</p>
</div>
</div>
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/messages/layout.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/messages/layout.tsx
index e1ae2e5a8e..fa046f4e95 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/messages/layout.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/messages/layout.tsx
@@ -6,6 +6,7 @@ import useWorkspace from "@/lib/swr/use-workspace";
import { NavButton } from "@/ui/layout/page-content/nav-button";
import { MessagesContext, MessagesPanel } from "@/ui/messages/messages-context";
import { MessagesList } from "@/ui/messages/messages-list";
+import { PartnerSelector } from "@/ui/partners/partner-selector";
import { Button, useRouterStuff } from "@dub/ui";
import { Msgs, Pen2 } from "@dub/ui/icons";
import { useParams, useRouter } from "next/navigation";
@@ -59,15 +60,20 @@ function CapableLayout({ children }: { children: ReactNode }) {
Messages
</h1>
</div>
- <Button
- variant="secondary"
- icon={<Pen2 className="size-4" />}
- className="size-8 rounded-lg p-0"
- onClick={() => {
- if (partnerId)
- router.push(`/${workspaceSlug}/program/messages?new=true`);
- else queryParams({ set: { new: "true" } });
- }}
+ <PartnerSelector
+ selectedPartnerId={partnerId ?? null}
+ setSelectedPartnerId={(id) =>
+ router.push(`/${workspaceSlug}/program/messages/${id}`)
+ }
+ trigger={
+ <Button
+ type="button"
+ variant="secondary"
+ icon={<Pen2 className="size-4" />}
+ className="size-8 rounded-lg p-0"
+ />
+ }
+ matchTriggerWidth={false}
/>
</div>
<div className="scrollbar-hide grow overflow-y-auto">
@@ -102,19 +108,6 @@ function CapableLayout({ children }: { children: ReactNode }) {
can also start a conversation at any time.
</p>
</div>
-
- <Button
- variant="primary"
- className="mt-6 h-8 w-fit rounded-lg"
- text="Compose message"
- onClick={() => {
- if (partnerId)
- router.push(
- `/${workspaceSlug}/program/messages?new=true`,
- );
- else queryParams({ set: { new: "true" } });
- }}
- />
</div>
)}
</div>
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/messages/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/messages/page-client.tsx
index dc45bd354f..5d99e61c38 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/messages/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/messages/page-client.tsx
@@ -1,25 +1,11 @@
"use client";
-import useWorkspace from "@/lib/swr/use-workspace";
import { useMessagesContext } from "@/ui/messages/messages-context";
-import { PartnerSelector } from "@/ui/partners/partner-selector";
-import { useRouterStuff } from "@dub/ui";
import { ChevronLeft, Msgs } from "@dub/ui/icons";
-import { useRouter } from "next/navigation";
-import { useState } from "react";
export function ProgramMessagesPageClient() {
- const { slug: workspaceSlug } = useWorkspace();
const { setCurrentPanel } = useMessagesContext();
- const router = useRouter();
- const { searchParams, queryParams } = useRouterStuff();
-
- // Short-lived state to display the selected partner while the next page loads
- const [selectedPartnerId, setSelectedPartnerId] = useState<string | null>(
- null,
- );
-
return (
<div className="flex h-full flex-col">
<div className="border-border-subtle flex h-12 items-center gap-2 border-b px-4 sm:h-16 sm:px-6">
@@ -27,34 +13,17 @@ export function ProgramMessagesPageClient() {
type="button"
onClick={() => {
setCurrentPanel("index");
- queryParams({ del: "new" });
}}
className="@[800px]/page:hidden rounded-lg p-1.5 text-neutral-500 transition-colors hover:bg-neutral-100 hover:text-neutral-900"
>
<ChevronLeft className="size-3.5" />
</button>
- {searchParams.get("new") && (
- <div className="animate-slide-up-fade flex items-center gap-3 [--offset:10px] [animation-duration:1s]">
- <span className="text-content-subtle text-lg font-medium">To</span>
- <div className="min-w-24 sm:w-64">
- <PartnerSelector
- selectedPartnerId={selectedPartnerId}
- setSelectedPartnerId={(id) => {
- setSelectedPartnerId(id);
- router.push(`/${workspaceSlug}/program/messages/${id}`);
- }}
- />
- </div>
- </div>
- )}
</div>
<div className="flex grow flex-col items-center justify-center gap-4">
<Msgs className="text-content-muted size-10" />
<p className="text-content-muted text-sm font-medium">
- {searchParams.get("new")
- ? "Select a partner to message"
- : "Select or compose a message"}
+ Select or compose a message
</p>
</div>
</div>
diff --git a/apps/web/ui/messages/messages-panel.tsx b/apps/web/ui/messages/messages-panel.tsx
index a6cb1da631..0671530477 100644
--- a/apps/web/ui/messages/messages-panel.tsx
+++ b/apps/web/ui/messages/messages-panel.tsx
@@ -39,7 +39,7 @@ export function MessagesPanel({
const [typedMessage, setTypedMessage] = useState("");
const sendMessage = () => {
- if (!typedMessage.trim()) return;
+ if (!messages || !typedMessage.trim()) return;
onSendMessage(typedMessage.trim());
setTypedMessage("");
@@ -213,7 +213,6 @@ export function MessagesPanel({
autoFocus={!isMobile}
className="placeholder:text-content-subtle block max-h-24 w-full resize-none border-none p-3 text-base focus:ring-0 sm:text-sm"
placeholder={placeholder}
- disabled={!messages}
value={typedMessage}
maxLength={MAX_MESSAGE_LENGTH}
onChange={(e) => setTypedMessage(e.currentTarget.value)}
diff --git a/apps/web/ui/partners/partner-selector.tsx b/apps/web/ui/partners/partner-selector.tsx
index 9edcb3cd00..6d772899cc 100644
--- a/apps/web/ui/partners/partner-selector.tsx
+++ b/apps/web/ui/partners/partner-selector.tsx
@@ -1,20 +1,21 @@
import usePartners from "@/lib/swr/use-partners";
import { PARTNERS_MAX_PAGE_SIZE } from "@/lib/zod/schemas/partners";
-import { Combobox } from "@dub/ui";
+import { Combobox, ComboboxProps } from "@dub/ui";
import { cn, OG_AVATAR_URL } from "@dub/utils";
import { useEffect, useMemo, useState } from "react";
import { useDebounce } from "use-debounce";
-interface PartnerSelectorProps {
+type PartnerSelectorProps = {
selectedPartnerId: string | null;
setSelectedPartnerId: (partnerId: string) => void;
disabled?: boolean;
-}
+} & Partial<ComboboxProps<false, any>>;
export function PartnerSelector({
selectedPartnerId,
setSelectedPartnerId,
disabled,
+ ...rest
}: PartnerSelectorProps) {
const [search, setSearch] = useState("");
const [useAsync, setUseAsync] = useState(false);
@@ -76,6 +77,7 @@ export function PartnerSelector({
<Combobox
options={loading ? undefined : partnerOptions}
setSelected={(option) => {
+ if (!option) return;
setSelectedPartnerId(option.value);
}}
selected={selectedOption}
@@ -96,6 +98,7 @@ export function PartnerSelector({
"focus:ring-1 focus:ring-neutral-500 focus:border-neutral-500 transition-none",
),
}}
+ {...rest}
>
{selectedPartnersLoading ? (
<div className="my-0.5 h-5 w-1/3 animate-pulse rounded bg-neutral-200" />
diff --git a/apps/web/ui/partners/program-selector.tsx b/apps/web/ui/partners/program-selector.tsx
index f56f09ad8d..61c9d1d189 100644
--- a/apps/web/ui/partners/program-selector.tsx
+++ b/apps/web/ui/partners/program-selector.tsx
@@ -1,18 +1,19 @@
import useProgramEnrollments from "@/lib/swr/use-program-enrollments";
-import { Combobox } from "@dub/ui";
+import { Combobox, ComboboxProps } from "@dub/ui";
import { cn, OG_AVATAR_URL } from "@dub/utils";
import { useMemo, useState } from "react";
-interface ProgramSelectorProps {
+type ProgramSelectorProps = {
selectedProgramSlug: string | null;
setSelectedProgramSlug: (programSlug: string) => void;
disabled?: boolean;
-}
+} & Partial<ComboboxProps<false, any>>;
export function ProgramSelector({
selectedProgramSlug,
setSelectedProgramSlug,
disabled,
+ ...rest
}: ProgramSelectorProps) {
const [openPopover, setOpenPopover] = useState(false);
@@ -58,6 +59,7 @@ export function ProgramSelector({
<Combobox
options={isLoading ? undefined : programOptions}
setSelected={(option) => {
+ if (!option) return;
setSelectedProgramSlug(option.value);
}}
selected={selectedOption}
@@ -76,6 +78,7 @@ export function ProgramSelector({
"focus:ring-1 focus:ring-neutral-500 focus:border-neutral-500 transition-none",
),
}}
+ {...rest}
>
{selectedOption?.label}
</Combobox>
diff --git a/packages/ui/src/combobox/index.tsx b/packages/ui/src/combobox/index.tsx
index 1e74482f61..0735e9058b 100644
--- a/packages/ui/src/combobox/index.tsx
+++ b/packages/ui/src/combobox/index.tsx
@@ -49,6 +49,7 @@ export type ComboboxProps<
: (option: ComboboxOption<TMeta> | null) => void;
onSelect?: (option: ComboboxOption<TMeta>) => void;
options?: ComboboxOption<TMeta>[];
+ trigger?: ReactNode;
icon?: Icon | ReactNode;
placeholder?: ReactNode;
searchPlaceholder?: string;
@@ -84,6 +85,7 @@ export function Combobox({
setSelected,
onSelect,
options,
+ trigger,
icon: Icon,
placeholder = "Select...",
searchPlaceholder = "Search...",
@@ -311,41 +313,43 @@ export function Combobox({
</AnimatedSizeContainer>
}
>
- <Button
- variant="secondary"
- {...buttonProps}
- className={cn(buttonProps?.className, "flex gap-2")}
- textWrapperClassName={cn(
- buttonProps?.textWrapperClassName,
- "w-full flex items-center justify-start",
- )}
- text={
- <>
- <div className="min-w-0 grow truncate text-left">
- {children ||
- selected.map((option) => option.label).join(", ") ||
- placeholder}
- </div>
- {caret &&
- (caret === true ? (
- <ChevronDown
- className={`ml-1 size-4 shrink-0 text-neutral-400 transition-transform duration-75 group-data-[state=open]:rotate-180`}
- />
+ {trigger ?? (
+ <Button
+ variant="secondary"
+ {...buttonProps}
+ className={cn(buttonProps?.className, "flex gap-2")}
+ textWrapperClassName={cn(
+ buttonProps?.textWrapperClassName,
+ "w-full flex items-center justify-start",
+ )}
+ text={
+ <>
+ <div className="min-w-0 grow truncate text-left">
+ {children ||
+ selected.map((option) => option.label).join(", ") ||
+ placeholder}
+ </div>
+ {caret &&
+ (caret === true ? (
+ <ChevronDown
+ className={`ml-1 size-4 shrink-0 text-neutral-400 transition-transform duration-75 group-data-[state=open]:rotate-180`}
+ />
+ ) : (
+ caret
+ ))}
+ </>
+ }
+ icon={
+ Icon ? (
+ isReactNode(Icon) ? (
+ Icon
) : (
- caret
- ))}
- </>
- }
- icon={
- Icon ? (
- isReactNode(Icon) ? (
- Icon
- ) : (
- <Icon className="size-4 shrink-0" />
- )
- ) : undefined
- }
- />
+ <Icon className="size-4 shrink-0" />
+ )
+ ) : undefined
+ }
+ />
+ )}
</Popover>
);
}