forked from djyde/cusdis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getting-start.tsx
130 lines (111 loc) · 3.08 KB
/
getting-start.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { Box, Container, Stack, Title, Text, Button, TextInput, Image } from "@mantine/core"
import { notifications } from "@mantine/notifications"
import router from "next/router"
import React from "react"
import { useMutation } from "react-query"
import { Head } from "../components/Head"
import { ProjectService } from "../service/project.service"
import { apiClient } from "../utils.client"
import { getSession } from "../utils.server"
export const createProject = async (body: { title: string }) => {
const res = await apiClient.post("/projects", {
title: body.title,
})
return res.data
}
function GettingStart() {
const createProjectMutation = useMutation(createProject)
const titleInputRef = React.useRef<HTMLInputElement>(null)
async function onClickCreateProject() {
if (!titleInputRef.current.value) {
return
}
await createProjectMutation.mutate(
{
title: titleInputRef.current.value,
},
{
onSuccess(data) {
notifications.show({
title: "Project created",
message: "Redirecting to project dashboard",
color: 'green'
})
router.push(`/dashboard/project/${data.data.id}`, null, {
shallow: true,
})
},
onError(data: any) {
const {
error: message,
status: statusCode
} = data.response.data
notifications.show({
title: "Error",
message,
color: 'yellow'
})
}
}
)
}
return (
<>
<Head title="Add new site - Cusdis" />
<Container mt={120}>
<Stack>
<Image width={48} src="/images/artworks/logo-256.png" mb="16">
</Image>
<Stack spacing={4}>
<Title order={2} weight={500}>
Let's create a new site
</Title>
<Text color="gray">
Give your site a name, and you can start using Cusdis.
</Text>
</Stack>
<Stack spacing={8}>
<Text>
Site name
</Text>
<TextInput placeholder="My personal blog" ref={titleInputRef} />
</Stack>
<Box>
<Button onClick={_ => void onClickCreateProject()} loading={createProjectMutation.isLoading} color="blue">Create</Button>
</Box>
</Stack>
</Container>
</>
)
}
export async function getServerSideProps(ctx) {
const session = await getSession(ctx.req)
if (!session) {
return {
redirect: {
destination: '/api/auth/signin',
permanent: false
}
}
}
// const projectService = new ProjectService(ctx.req)
// const defaultProject = await projectService.getFirstProject(session.uid, {
// select: {
// id: true
// }
// })
// if (defaultProject) {
// // redirect to project dashboard
// return {
// redirect: {
// destination: `/dashboard/project/${defaultProject.id}`,
// permanent: false
// }
// }
// }
return {
props: {
}
}
}
export default GettingStart