Skip to content
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

refactor(web-ui): move chat page to chat module #832

Merged
merged 2 commits into from
Jul 13, 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
11 changes: 8 additions & 3 deletions services/web-ui/src/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import { NavigationTrackingProvider } from "src/core/tracking/NavigationTrackingProvider";
import { BlogPostListPage } from "src/features/blogs/pages/BlogPostListPage";
import { BlogPostPage } from "src/features/blogs/pages/BlogPostPage";
import { ConversationsPage } from "src/features/chat/pages/ConversationsPage";
import { ChatPage } from "src/pages/ChatPage";
import { ChatListPage } from "src/features/chat/pages/ChatListPage";
import { ChatPage } from "src/features/chat/pages/ChatPage";
import { CreateChatPage } from "src/features/chat/pages/CreateChatPage";

Check warning on line 11 in services/web-ui/src/Router.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/Router.tsx#L9-L11

Added lines #L9 - L11 were not covered by tests
import { CreateOrganizationPage } from "src/pages/CreateOrganizationPage";
import { CurrentOrganizationPage } from "src/pages/CurrentOrganizationPage";
import { CurrentProfilePage } from "src/pages/CurrentProfilePage";
Expand Down Expand Up @@ -44,7 +45,11 @@
},
{
path: "/chat",
element: <ConversationsPage />,
element: <ChatListPage />,
},
{
path: "/chat/create",
element: <CreateChatPage />,
},
{
path: "/chat/:id",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ReactElement } from "react";

import { List } from "@mui/material";

import { ChatConversationDetails } from "src/api";

import { ConversationListItem } from "./components/ConversationListItem";

export interface ChatListPageComponentProps {
data: ChatConversationDetails[];
}

export function ChatListPageComponent({
data,
}: ChatListPageComponentProps): ReactElement {
return (

Check warning on line 16 in services/web-ui/src/features/chat/pages/ChatListPage/ChatListPage.component.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/ChatListPage/ChatListPage.component.tsx#L15-L16

Added lines #L15 - L16 were not covered by tests
<List>
{data.map((conversation, index) => (
<ConversationListItem

Check warning on line 19 in services/web-ui/src/features/chat/pages/ChatListPage/ChatListPage.component.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/ChatListPage/ChatListPage.component.tsx#L19

Added line #L19 was not covered by tests
divider={index < data.length - 1}
key={conversation.id}
data={conversation}
/>
))}
</List>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,47 @@ import { useTranslation } from "src/core/i18n";
import { useQuery } from "src/core/query";
import { ErrorView } from "src/views/ErrorView";

import { ConversationsPageComponent } from "./ConversationsPage.component";
import { ConversationsPageNav } from "./ConversationsPage.nav";
import { ConversationsPageSkeleton } from "./ConversationsPage.skeleton";
import { ChatListPageComponent } from "./ChatListPage.component";
import { ChatListPageNav } from "./ChatListPage.nav";
import { ChatListPageSkeleton } from "./ChatListPage.skeleton";

export function ConversationsPageContainer(): ReactElement {
export function ChatListPageContainer(): ReactElement {
const { t } = useTranslation("connections");

const { error, data, isPending } = useQuery({
queryKey: ["chat-conversations"],
queryKey: ["chats"],
queryFn: () => chatsApi.getConversations(),
});

if (error) {
return (
<ConversationsPageNav>
<ChatListPageNav>
<ErrorView message="Unable to get chats" />
</ConversationsPageNav>
</ChatListPageNav>
);
}

if (isPending) {
return (
<ConversationsPageNav>
<ConversationsPageSkeleton />
</ConversationsPageNav>
<ChatListPageNav>
<ChatListPageSkeleton />
</ChatListPageNav>
);
}

if (!data || data.length === 0) {
return (
<ConversationsPageNav>
<ChatListPageNav>
<Typography sx={{ paddingTop: 1 }} gutterBottom>
{t("no-connections")}
</Typography>
</ConversationsPageNav>
</ChatListPageNav>
);
}

return (
<ConversationsPageNav>
<ConversationsPageComponent data={data} />
</ConversationsPageNav>
<ChatListPageNav>
<ChatListPageComponent data={data} />
</ChatListPageNav>
);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React, { ReactNode } from "react";
import { ReactElement, ReactNode } from "react";

import { Box, Typography } from "@mui/material";

import { useTranslation } from "src/core/i18n";

export interface ConversationsPageNavProps {
export interface ChatListPageNavProps {
children: ReactNode;
}

export function ConversationsPageNav({
export function ChatListPageNav({
children,
}: ConversationsPageNavProps): React.ReactElement {
}: ChatListPageNavProps): ReactElement {

Check warning on line 13 in services/web-ui/src/features/chat/pages/ChatListPage/ChatListPage.nav.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/ChatListPage/ChatListPage.nav.tsx#L13

Added line #L13 was not covered by tests
const { t } = useTranslation("connections");

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ReactElement } from "react";

import { List, ListItem, Skeleton } from "@mui/material";

export function ChatListPageSkeleton(): ReactElement {
return (

Check warning on line 6 in services/web-ui/src/features/chat/pages/ChatListPage/ChatListPage.skeleton.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/ChatListPage/ChatListPage.skeleton.tsx#L6

Added line #L6 was not covered by tests
<List>
<ListItem divider>
<Skeleton height={50} width="100%" />
</ListItem>

<ListItem divider>
<Skeleton height={50} width="100%" />
</ListItem>

<ListItem divider>
<Skeleton height={50} width="100%" />
</ListItem>
</List>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Meta } from "@storybook/react";

import { ChatConversationDetails } from "src/api";

import { ConversationsPageComponent } from "./ConversationsPage.component";
import { ChatListPageComponent } from "./ChatListPage.component";

const MATCHES_DATA: ChatConversationDetails[] = [
{
Expand All @@ -25,9 +25,9 @@ const MATCHES_DATA: ChatConversationDetails[] = [
];

export default {
title: "Pages/Conversations/Views",
title: "Pages/Chats/Views",
} as Meta;

export const Default = {
render: () => <ConversationsPageComponent data={MATCHES_DATA} />,
render: () => <ChatListPageComponent data={MATCHES_DATA} />,
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ReactQueryTestProvider, TestRouter, render, screen } from "src/test";

import { ConversationsPage } from ".";
import { ChatListPage } from ".";

describe.skip("<ConversationsPage />", () => {
describe.skip("<ChatListPage />", () => {
it("renders message when no matches", async () => {
render(
<TestRouter>
<ReactQueryTestProvider>
<ConversationsPage />
<ChatListPage />
</ReactQueryTestProvider>
</TestRouter>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ChatListPageContainer as ChatListPage } from "./ChatListPage.container";

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { ReactElement, useState } from "react";

Check warning on line 1 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx#L1

Added line #L1 was not covered by tests

import { Autocomplete, TextField } from "@mui/material";

Check warning on line 3 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx#L3

Added line #L3 was not covered by tests

import { chatsApi, organizationsApi } from "src/apis";
import { Button } from "src/components/ui";
import { useMutation, useQuery } from "src/core/query";
import { ErrorView } from "src/views/ErrorView";

Check warning on line 8 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx#L5-L8

Added lines #L5 - L8 were not covered by tests

import { CreateChatPageNav } from "./CreateChatPage.nav";
import { CreateChatPageSkeleton } from "./CreateChatPage.skeleton";

Check warning on line 11 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx#L10-L11

Added lines #L10 - L11 were not covered by tests

interface Option {
id: number;
label: string;
}

export function CreateChatPageContainer(): ReactElement {
const { error, data, isPending } = useQuery({

Check warning on line 19 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx#L18-L19

Added lines #L18 - L19 were not covered by tests
queryKey: ["members"],
queryFn: () => organizationsApi.getCurrentOrganizationMembers(),

Check warning on line 21 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx#L21

Added line #L21 was not covered by tests
});

const [members, setMembers] = useState<Option[]>([]);

Check warning on line 24 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx#L24

Added line #L24 was not covered by tests

const createChatMutation = useMutation({
mutationFn: () => chatsApi.getConversations(),

Check warning on line 27 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx#L26-L27

Added lines #L26 - L27 were not covered by tests
});

if (error) {
return (

Check warning on line 31 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx#L31

Added line #L31 was not covered by tests
<CreateChatPageNav>
<ErrorView />
</CreateChatPageNav>
);
}

if (isPending) {
return (

Check warning on line 39 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx#L39

Added line #L39 was not covered by tests
<CreateChatPageNav>
<CreateChatPageSkeleton />
</CreateChatPageNav>
);
}

const options = data.map((x) => ({ id: x.id, label: x.name }));

Check warning on line 46 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx#L46

Added line #L46 was not covered by tests

return (

Check warning on line 48 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx#L48

Added line #L48 was not covered by tests
<CreateChatPageNav>
<Autocomplete
multiple
onChange={(_, newValue) => setMembers(newValue)}

Check warning on line 52 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx#L52

Added line #L52 was not covered by tests
options={options}
renderInput={(params) => <TextField label="Members" {...params} />}

Check warning on line 54 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx#L54

Added line #L54 was not covered by tests
value={members}
/>

<Button
disabled={members.length === 0}
loading={createChatMutation.isPending}
onClick={() => createChatMutation.mutate()}

Check warning on line 61 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.container.tsx#L61

Added line #L61 was not covered by tests
sx={{ mt: 2 }}
variant="contained"
>
Create
</Button>
</CreateChatPageNav>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ReactElement, ReactNode } from "react";

import { Box } from "@mui/material";

Check warning on line 3 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.nav.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.nav.tsx#L3

Added line #L3 was not covered by tests

interface CreateChatPageNavProps {
children: ReactNode;
}

export function CreateChatPageNav({

Check warning on line 9 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.nav.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.nav.tsx#L9

Added line #L9 was not covered by tests
children,
}: CreateChatPageNavProps): ReactElement {
return <Box sx={{ p: 2 }}>{children}</Box>;

Check warning on line 12 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.nav.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.nav.tsx#L11-L12

Added lines #L11 - L12 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ReactElement } from "react";

export function CreateChatPageSkeleton(): ReactElement {
return <>Loading...</>;

Check warning on line 4 in services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.skeleton.tsx

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/CreateChatPage.skeleton.tsx#L3-L4

Added lines #L3 - L4 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { CreateChatPageContainer as CreateChatPage } from "./CreateChatPage.container";

Check warning on line 1 in services/web-ui/src/features/chat/pages/CreateChatPage/index.ts

View check run for this annotation

Codecov / codecov/patch

services/web-ui/src/features/chat/pages/CreateChatPage/index.ts#L1

Added line #L1 was not covered by tests
Loading