Skip to content

Commit eb734aa

Browse files
committed
Merge branch 'main' into DIAL-27-Add-send-message-to-user
2 parents 0b72aaf + 7a4d347 commit eb734aa

File tree

96 files changed

+3098
-1721
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+3098
-1721
lines changed

client/.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ module.exports = {
2323
caughtErrorsIgnorePattern: '^_',
2424
},
2525
],
26+
'@typescript-eslint/ban-ts-comment': 'off',
2627
},
2728
};

client/package-lock.json

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"cmdk": "^0.2.1",
5151
"crypto-js": "^4.2.0",
5252
"date-fns": "^3.3.1",
53+
"dayjs": "^1.11.10",
5354
"embla-carousel-react": "^8.0.0-rc23",
5455
"firebase": "^10.8.0",
5556
"i18next": "^23.9.0",
@@ -65,9 +66,11 @@
6566
"react-hook-form": "^7.50.1",
6667
"react-i18next": "^14.0.5",
6768
"react-resizable-panels": "^2.0.9",
69+
"react-router-dom": "^6.22.2",
6870
"sonner": "^1.4.0",
6971
"tailwind-merge": "^2.2.1",
7072
"tailwindcss-animate": "^1.0.7",
73+
"usehooks-ts": "^2.15.1",
7174
"vaul": "^0.9.0",
7275
"zod": "^3.22.4",
7376
"zustand": "^4.5.1"

client/src/apis/channel.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { ENDPOINTS } from '@/constants';
2+
import http_client from '@/lib/http-client';
3+
import { TChannelInput } from '@/lib/schema/channel';
4+
import {
5+
TChannelQuery,
6+
TChannelType,
7+
TChannelWithChannelType,
8+
} from '@/types/channel';
9+
import { TBaseResponse, TResPagination } from '@/types/share';
10+
11+
class ChannelApi {
12+
getChannelType(id: string): Promise<TBaseResponse<TChannelType>> {
13+
return http_client.get(`${ENDPOINTS.CHANNEL.TYPES}/${id}`);
14+
}
15+
16+
getChannelTypes(): Promise<TBaseResponse<TChannelType[]>> {
17+
return http_client.get(ENDPOINTS.CHANNEL.TYPES);
18+
}
19+
20+
getChannels(
21+
query?: TChannelQuery
22+
): Promise<TResPagination<TChannelWithChannelType>> {
23+
return http_client.get(ENDPOINTS.CHANNEL.INDEX, {
24+
params: query,
25+
});
26+
}
27+
28+
create(
29+
data: TChannelInput
30+
): Promise<TBaseResponse<TChannelWithChannelType>> {
31+
return http_client.post(ENDPOINTS.CHANNEL.INDEX, data);
32+
}
33+
34+
update(
35+
id: string,
36+
data: TChannelInput
37+
): Promise<TBaseResponse<TChannelWithChannelType>> {
38+
return http_client.put(`${ENDPOINTS.CHANNEL.INDEX}/${id}`, data);
39+
}
40+
41+
delete(id: string): Promise<TBaseResponse<null>> {
42+
return http_client.delete(`${ENDPOINTS.CHANNEL.DELETE}/${id}`);
43+
}
44+
45+
deleteMany(ids: string[]): Promise<TBaseResponse<null>> {
46+
return http_client.delete(ENDPOINTS.CHANNEL.DELETES, {
47+
data: { ids },
48+
});
49+
}
50+
}
51+
52+
export const channelApi = new ChannelApi();

client/src/app.tsx

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import { createBrowserRouter, redirect } from 'react-router-dom';
2+
import { queryClient } from '@/lib/query-client';
3+
import i18n from './i18n';
4+
import {
5+
Channels,
6+
ForgotPassword,
7+
Login,
8+
Mail,
9+
Profiles,
10+
Register,
11+
SetPassword,
12+
} from '@/pages';
13+
import { useAppLayoutStore, useSettingStore, useUserStore } from '@/store';
14+
import {
15+
currentUserQueryOptions,
16+
settingQueryOption,
17+
} from '@/lib/query-options';
18+
import { AppLayout, AuthLayout, SettingLayout } from '@/components/layouts';
19+
import { TChannelQuery } from './types/channel';
20+
import { queryStringToObject } from './utils';
21+
import { queryChannelsOption } from './lib/query-options/channel';
22+
23+
export const router = createBrowserRouter([
24+
{
25+
children: [
26+
{
27+
loader: async ({ request }) => {
28+
const redirectUrl = new URL(request.url).searchParams.get(
29+
'redirect'
30+
);
31+
const user = await queryClient.ensureQueryData(
32+
currentUserQueryOptions()
33+
);
34+
35+
if (user) {
36+
return redirect(redirectUrl || '/chatbots');
37+
}
38+
39+
return null;
40+
},
41+
Component: AuthLayout,
42+
children: [
43+
{
44+
path: '/login',
45+
Component: Login,
46+
index: true,
47+
},
48+
{
49+
path: '/register',
50+
Component: Register,
51+
},
52+
{
53+
path: '/forgot-password',
54+
Component: ForgotPassword,
55+
},
56+
{
57+
path: '/set-password',
58+
Component: SetPassword,
59+
},
60+
],
61+
},
62+
{
63+
Component: AppLayout,
64+
loader: async () => {
65+
const user = await queryClient.ensureQueryData(
66+
currentUserQueryOptions()
67+
);
68+
69+
const url = new URLSearchParams({
70+
redirect: location.href,
71+
});
72+
73+
if (!user) {
74+
return redirect(`/login?${url.toString()}`);
75+
}
76+
77+
useUserStore.getState().setUser(user);
78+
79+
return null;
80+
},
81+
children: [
82+
{
83+
path: '/dashboard',
84+
index: true,
85+
loader: async () => {
86+
return redirect('/chatbots');
87+
},
88+
},
89+
{
90+
path: '/chatbots',
91+
element: <div>a</div>,
92+
loader: () => {
93+
useAppLayoutStore
94+
.getState()
95+
.setTitle(i18n.t('common:chatbots'));
96+
97+
return null;
98+
},
99+
},
100+
{
101+
path: '/channels',
102+
Component: Channels,
103+
loader: async ({ request }) => {
104+
const query: TChannelQuery = queryStringToObject(
105+
request.url
106+
);
107+
108+
await queryClient.ensureQueryData(
109+
queryChannelsOption(query)
110+
);
111+
112+
useAppLayoutStore
113+
.getState()
114+
.setTitle(i18n.t('common:channels'));
115+
116+
return null;
117+
},
118+
},
119+
{
120+
path: '/settings',
121+
Component: SettingLayout,
122+
loader: async () => {
123+
const data =
124+
await queryClient.ensureQueryData(settingQueryOption());
125+
126+
useSettingStore.getState().setSetting(data);
127+
useAppLayoutStore
128+
.getState()
129+
.setTitle(i18n.t('common:settings'));
130+
131+
return null;
132+
},
133+
children: [
134+
{
135+
path: 'mail',
136+
Component: Mail,
137+
},
138+
{
139+
path: 'profiles',
140+
Component: Profiles,
141+
},
142+
{
143+
index: true,
144+
loader: async () => {
145+
return redirect('/settings/profiles');
146+
},
147+
},
148+
],
149+
},
150+
],
151+
},
152+
{
153+
path: '/',
154+
element: <div>Hi</div>,
155+
},
156+
],
157+
},
158+
]);

0 commit comments

Comments
 (0)