Skip to content

feat: Convo attachments in Sidebar #454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/web/src/app/[orgShortCode]/_components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ function OrgMenu({ collapsed }: { collapsed: boolean }) {
method: 'POST',
credentials: 'include'
});
queryClient.removeQueries();
router.replace('/');
await queryClient.invalidateQueries();
},
{
onError: (error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { cn, generateAvatarUrl, getInitials } from '@/src/lib/utils';
import {
Avatar,
Box,
Badge,
Dialog,
Flex,
Heading,
Expand Down Expand Up @@ -32,11 +33,18 @@ import { useRouter } from 'next/navigation';
export default function ChatSideBar({
participants,
convoId,
convoHidden
convoHidden,
attachments
}: {
participants: NonNullable<ReturnType<typeof formatParticipantData>>[];
convoId: TypeId<'convos'>;
convoHidden: boolean | null;
attachments: {
name: string;
url: string;
type: string;
publicId: TypeId<'convoAttachments'>;
}[];
}) {
const orgShortCode = useGlobalStore((state) => state.currentOrg.shortCode);
const [participantOpen, setParticipantOpen] = useState(false);
Expand Down Expand Up @@ -93,7 +101,8 @@ export default function ChatSideBar({
<Flex className="border-gray-11 h-full w-full border-l">
<Flex
direction="column"
className="w-full">
className="w-full"
gap="2">
<Flex
className="w-full p-1"
justify="between"
Expand Down Expand Up @@ -168,6 +177,23 @@ export default function ChatSideBar({
</Flex>
))}
</Flex>
{attachments.length > 0 ? (
<div className="flex flex-col gap-2 px-2">
<span className="font-bold">Attachments</span>
<div className="flex w-full flex-wrap gap-2">
{attachments.map((attachment) => (
<a
target="_blank"
key={attachment.publicId}
href={attachment.url}>
<Badge className="flex w-fit max-w-full truncate p-1">
{attachment.name}
</Badge>
</a>
))}
</div>
</div>
) : null}
</Flex>
</Flex>
<ModalRoot />
Expand Down
16 changes: 16 additions & 0 deletions apps/web/src/app/[orgShortCode]/convo/[convoId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ import AttachmentButton, {
type ConvoAttachmentUpload
} from '../new/attachment-button';
import { stringify } from 'superjson';
import { env } from 'next-runtime-env';
import { type Editor as EditorType } from '@u22n/tiptap/react';

const STORAGE_URL = env('NEXT_PUBLIC_STORAGE_URL');

const replyToMessageAtom = atom<null | TypeId<'convoEntries'>>(null);
const selectedEmailIdentityAtom = atom<null | TypeId<'emailIdentities'>>(null);

Expand Down Expand Up @@ -102,6 +105,18 @@ function ConvoView({ convoId }: { convoId: TypeId<'convos'> }) {
return messages;
}, [data]);

const attachments = useMemo(() => {
if (!convoData) return [];
return convoData.data.attachments
.filter((f) => !f.inline)
.map((attachment) => ({
name: attachment.fileName,
url: `${STORAGE_URL}/attachment/${orgShortCode}/${attachment.publicId}/${attachment.fileName}`,
type: attachment.type,
publicId: attachment.publicId
}));
}, [convoData, orgShortCode]);

useEffect(() => {
const lastMessage = allMessages.at(-1);
setReplyTo(() => lastMessage?.publicId ?? null);
Expand Down Expand Up @@ -243,6 +258,7 @@ function ConvoView({ convoId }: { convoId: TypeId<'convos'> }) {
participants={allParticipants}
convoId={convoId}
convoHidden={convoHidden}
attachments={attachments}
/>
</Flex>
);
Expand Down
45 changes: 38 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.