Skip to content

Commit be4a72e

Browse files
committed
✨(frontend) link to create new doc
We create a special URL to create a new doc, we can set the doc with the URL param to set the visibility, the permission, the accesses, the title.
1 parent f9ff578 commit be4a72e

File tree

1 file changed

+87
-0
lines changed
  • src/frontend/apps/impress/src/pages/docs/new

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import Head from 'next/head';
2+
import { useSearchParams } from 'next/navigation';
3+
import { useRouter } from 'next/router';
4+
import { ReactElement, useEffect } from 'react';
5+
6+
import { Loading } from '@/components';
7+
import { LinkReach, useCreateDoc } from '@/features/docs/doc-management';
8+
import { useUpdateDocLink } from '@/features/docs/doc-share/api/useUpdateDocLink';
9+
import { useSkeletonStore } from '@/features/skeletons';
10+
import { MainLayout } from '@/layouts';
11+
import { NextPageWithLayout } from '@/types/next';
12+
13+
const Page: NextPageWithLayout = () => {
14+
const { setIsSkeletonVisible } = useSkeletonStore();
15+
const router = useRouter();
16+
const searchParams = useSearchParams();
17+
const linkReach = searchParams.get('link-reach');
18+
const linkTitle = searchParams.get('title');
19+
const linkpermission = searchParams.get('linkpermission');
20+
const peoplesharing = searchParams.get('peoplesharing');
21+
22+
const {
23+
mutate: createDoc,
24+
//isSuccess: isDocCreated,
25+
data: doc,
26+
} = useCreateDoc({
27+
onSuccess: (doc) => {
28+
if (linkReach || linkpermission || peoplesharing) {
29+
return;
30+
}
31+
32+
router
33+
.push(`/docs/${doc.id}`)
34+
.then(() => {})
35+
.catch(() => {});
36+
},
37+
onError: () => {},
38+
});
39+
40+
const { mutate: updateDocLink } = useUpdateDocLink();
41+
42+
useEffect(() => {
43+
setIsSkeletonVisible(true);
44+
}, [setIsSkeletonVisible]);
45+
46+
useEffect(() => {
47+
if (doc) {
48+
return;
49+
}
50+
51+
createDoc();
52+
}, [createDoc, doc]);
53+
54+
useEffect(() => {
55+
if (!linkReach || !doc) {
56+
return;
57+
}
58+
59+
console.log('linkReach', linkReach);
60+
61+
if (!Object.values(LinkReach).includes(linkReach as LinkReach)) {
62+
throw new Error('Invalid link reach value');
63+
}
64+
65+
updateDocLink({
66+
id: doc.id,
67+
link_reach: linkReach as LinkReach,
68+
//link_role: linkRole,
69+
});
70+
}, [linkReach, doc, updateDocLink]);
71+
72+
return <Loading />;
73+
};
74+
75+
Page.getLayout = function getLayout(page: ReactElement) {
76+
return (
77+
<>
78+
<Head>
79+
<meta name="robots" content="noindex" />
80+
</Head>
81+
82+
<MainLayout enableResizablePanel={false}>{page}</MainLayout>
83+
</>
84+
);
85+
};
86+
87+
export default Page;

0 commit comments

Comments
 (0)