-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
account.tsx
225 lines (216 loc) · 8.36 KB
/
account.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import Head from 'next/head';
import MainLayout from '~/components/Layout/MainLayout';
import { Button } from '~/components/ui/button';
import Link from 'next/link';
import { UserAvatar } from '~/components/ui/avatar';
import {
Bell,
ChevronRight,
Download,
DownloadCloud,
FileDown,
Github,
HeartHandshakeIcon,
Star,
} from 'lucide-react';
import { signOut } from 'next-auth/react';
import { AppDrawer } from '~/components/ui/drawer';
import { SubmitFeedback } from '~/components/Account/SubmitFeedback';
import { UpdateDetails } from '~/components/Account/UpdateDetails';
import { api } from '~/utils/api';
import { type NextPageWithUser } from '~/types';
import { toast } from 'sonner';
import { env } from '~/env';
import { SubscribeNotification } from '~/components/Account/SubscribeNotification';
import { useState } from 'react';
import { LoadingSpinner } from '~/components/ui/spinner';
const AccountPage: NextPageWithUser = ({ user }) => {
const userQuery = api.user.me.useQuery();
const downloadQuery = api.user.downloadData.useMutation();
const [downloading, setDownloading] = useState(false);
async function downloadData() {
setDownloading(true);
const data = await downloadQuery.mutateAsync();
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = 'splitpro_data.json';
link.click();
URL.revokeObjectURL(url);
setDownloading(false);
}
return (
<>
<Head>
<title>Account</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<MainLayout title="Account" header={<div className="text-3xl font-semibold">Account</div>}>
<div className="mt-4 px-4">
<div className="flex items-center justify-between gap-2">
<div className="flex items-center gap-2">
<UserAvatar user={user} size={50} />
<div>
<div className="text-xl font-semibold">{userQuery.data?.name}</div>
<div className="text-sm text-gray-500">{user.email}</div>
</div>
</div>
<div>
{!userQuery.isLoading ? (
<UpdateDetails defaultName={userQuery.data?.name ?? ''} />
) : null}
</div>
</div>
<div className="mt-8 flex flex-col gap-4">
<Link href="https://twitter.com/KM_Koushik_" target="_blank">
<Button
variant="ghost"
className="text-md w-full justify-between px-0 hover:text-foreground/80"
>
<div className="flex items-center gap-4">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 1200 1227"
fill="none"
className="h-5 w-5 px-1"
>
<g clip-path="url(#clip0_1_2)">
<path
d="M714.163 519.284L1160.89 0H1055.03L667.137 450.887L357.328 0H0L468.492 681.821L0 1226.37H105.866L515.491 750.218L842.672 1226.37H1200L714.137 519.284H714.163ZM569.165 687.828L521.697 619.934L144.011 79.6944H306.615L611.412 515.685L658.88 583.579L1055.08 1150.3H892.476L569.165 687.854V687.828Z"
fill="white"
/>
</g>
<defs>
<clipPath id="clip0_1_2">
<rect width="1200" height="1227" fill="white" />
</clipPath>
</defs>
</svg>
Follow us on X
</div>
<ChevronRight className="h-6 w-6 text-gray-500" />
</Button>
</Link>
<Link href="https://github.com/oss-apps/split-pro" target="_blank">
<Button
variant="ghost"
className="text-md w-full justify-between px-0 hover:text-foreground/80"
>
<div className="flex items-center gap-4">
<Github className="h-5 w-5 text-gray-200" />
Star us on Github
</div>
<ChevronRight className="h-6 w-6 text-gray-500" />
</Button>
</Link>
<Link href="https://github.com/sponsors/KMKoushik" target="_blank">
<Button
variant="ghost"
className="text-md w-full justify-between px-0 hover:text-foreground/80"
>
<div className="flex items-center gap-4">
<HeartHandshakeIcon className="h-5 w-5 text-pink-600" />
Sponsor us
</div>
<ChevronRight className="h-6 w-6 text-gray-500" />
</Button>
</Link>
<SubmitFeedback />
<SubscribeNotification />
<Link href="https://www.producthunt.com/products/splitpro/reviews/new" target="_blank">
<Button
variant="ghost"
className="text-md w-full justify-between px-0 hover:text-foreground/80"
>
<div className="flex items-center gap-4">
<Star className="h-5 w-5 text-yellow-400" />
Write a review
</div>
<ChevronRight className="h-6 w-6 text-gray-500" />
</Button>
</Link>
<AppDrawer
trigger={
<div className="flex w-full justify-between px-0 py-2 text-[16px] font-medium text-gray-300 hover:text-foreground/80">
<div className="flex items-center gap-4">
<Download className="h-5 w-5 text-blue-500" />
Download App
</div>
<ChevronRight className="h-6x w-6 text-gray-500" />
</div>
}
leftAction="Close"
title="Download App"
className="h-[70vh]"
shouldCloseOnAction
>
<div className="flex flex-col gap-8">
<p>You can download SplitPro as a PWA to your home screen</p>
<p>
If you are using iOS, checkout this{' '}
<a
className="text-cyan-500 underline"
href="https://youtube.com/shorts/MQHeLOjr350"
target="_blank"
>
video
</a>
</p>
<p>
If you are using Android, checkout this{' '}
<a
className="text-cyan-500 underline"
href="https://youtube.com/shorts/04n7oKGzgOs"
target="_blank"
>
Video
</a>
</p>
</div>
</AppDrawer>
<Button
variant="ghost"
className="text-md w-full justify-between px-0 hover:text-foreground/80"
onClick={downloadData}
disabled={downloading}
>
<div className="flex items-center gap-4">
<FileDown className="h-5 w-5 text-teal-500" />
Download splitpro data
</div>
{downloading ? (
<LoadingSpinner />
) : (
<ChevronRight className="h-6 w-6 text-gray-500" />
)}
</Button>
<Link href="/import-splitwise">
<Button
variant="ghost"
className="text-md w-full justify-between px-0 hover:text-foreground/80"
>
<div className="flex items-center gap-4">
<DownloadCloud className="h-5 w-5 text-violet-500" />
Import from Splitwise
</div>
<ChevronRight className="h-6 w-6 text-gray-500" />
</Button>
</Link>
</div>
<div className="mt-2 flex justify-center">
<Button
variant="ghost"
className="text-orange-600 hover:text-orange-600/90 "
onClick={() => signOut()}
>
Logout
</Button>
</div>
</div>
</MainLayout>
</>
);
};
AccountPage.auth = true;
export default AccountPage;