@codaijs/keel 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/sail-installer.test.js +25 -25
- package/dist/sail-installer.js +174 -174
- package/dist/scaffold.js +68 -68
- package/package.json +58 -58
- package/sails/_template/addon.json +20 -20
- package/sails/_template/install.ts +402 -402
- package/sails/admin-dashboard/README.md +117 -117
- package/sails/admin-dashboard/addon.json +28 -28
- package/sails/admin-dashboard/files/backend/middleware/admin.ts +34 -34
- package/sails/admin-dashboard/files/backend/routes/admin.ts +243 -243
- package/sails/admin-dashboard/files/frontend/components/admin/StatsCard.tsx +40 -40
- package/sails/admin-dashboard/files/frontend/components/admin/UsersTable.tsx +240 -240
- package/sails/admin-dashboard/files/frontend/hooks/useAdmin.ts +149 -149
- package/sails/admin-dashboard/files/frontend/pages/admin/Dashboard.tsx +173 -173
- package/sails/admin-dashboard/files/frontend/pages/admin/UserDetail.tsx +203 -203
- package/sails/admin-dashboard/install.ts +305 -305
- package/sails/analytics/README.md +178 -178
- package/sails/analytics/addon.json +27 -27
- package/sails/analytics/files/frontend/components/AnalyticsProvider.tsx +58 -58
- package/sails/analytics/files/frontend/hooks/useAnalytics.ts +64 -64
- package/sails/analytics/files/frontend/lib/analytics.ts +103 -103
- package/sails/analytics/install.ts +297 -297
- package/sails/file-uploads/addon.json +30 -30
- package/sails/file-uploads/files/backend/routes/files.ts +198 -198
- package/sails/file-uploads/files/backend/schema/files.ts +36 -36
- package/sails/file-uploads/files/backend/services/file-storage.ts +128 -128
- package/sails/file-uploads/files/frontend/components/FileList.tsx +248 -248
- package/sails/file-uploads/files/frontend/components/FileUploadButton.tsx +147 -147
- package/sails/file-uploads/files/frontend/hooks/useFileUpload.ts +106 -106
- package/sails/file-uploads/files/frontend/hooks/useFiles.ts +118 -118
- package/sails/file-uploads/files/frontend/pages/Files.tsx +37 -37
- package/sails/file-uploads/install.ts +466 -466
- package/sails/gdpr/README.md +174 -174
- package/sails/gdpr/addon.json +27 -27
- package/sails/gdpr/files/backend/routes/gdpr.ts +140 -140
- package/sails/gdpr/files/backend/services/gdpr.ts +293 -293
- package/sails/gdpr/files/frontend/components/auth/ConsentCheckboxes.tsx +97 -97
- package/sails/gdpr/files/frontend/components/gdpr/AccountDeletionRequest.tsx +192 -192
- package/sails/gdpr/files/frontend/components/gdpr/DataExportButton.tsx +75 -75
- package/sails/gdpr/files/frontend/pages/PrivacyPolicy.tsx +186 -186
- package/sails/gdpr/install.ts +756 -756
- package/sails/google-oauth/README.md +121 -121
- package/sails/google-oauth/addon.json +22 -22
- package/sails/google-oauth/files/GoogleButton.tsx +50 -50
- package/sails/google-oauth/install.ts +252 -252
- package/sails/i18n/README.md +193 -193
- package/sails/i18n/addon.json +30 -30
- package/sails/i18n/files/frontend/components/LanguageSwitcher.tsx +108 -108
- package/sails/i18n/files/frontend/hooks/useLanguage.ts +31 -31
- package/sails/i18n/files/frontend/lib/i18n.ts +32 -32
- package/sails/i18n/files/frontend/locales/de/common.json +44 -44
- package/sails/i18n/files/frontend/locales/en/common.json +44 -44
- package/sails/i18n/install.ts +407 -407
- package/sails/push-notifications/README.md +163 -163
- package/sails/push-notifications/addon.json +31 -31
- package/sails/push-notifications/files/backend/routes/notifications.ts +153 -153
- package/sails/push-notifications/files/backend/schema/notifications.ts +31 -31
- package/sails/push-notifications/files/backend/services/notifications.ts +117 -117
- package/sails/push-notifications/files/frontend/components/PushNotificationInit.tsx +12 -12
- package/sails/push-notifications/files/frontend/hooks/usePushNotifications.ts +154 -154
- package/sails/push-notifications/install.ts +384 -384
- package/sails/r2-storage/addon.json +29 -29
- package/sails/r2-storage/files/backend/services/storage.ts +71 -71
- package/sails/r2-storage/files/frontend/components/ProfilePictureUpload.tsx +167 -167
- package/sails/r2-storage/install.ts +412 -412
- package/sails/rate-limiting/addon.json +20 -20
- package/sails/rate-limiting/files/backend/middleware/rate-limit-store.ts +104 -104
- package/sails/rate-limiting/files/backend/middleware/rate-limit.ts +137 -137
- package/sails/rate-limiting/install.ts +300 -300
- package/sails/registry.json +107 -107
- package/sails/stripe/README.md +214 -214
- package/sails/stripe/addon.json +24 -24
- package/sails/stripe/files/backend/routes/stripe.ts +154 -154
- package/sails/stripe/files/backend/schema/stripe.ts +74 -74
- package/sails/stripe/files/backend/services/stripe.ts +224 -224
- package/sails/stripe/files/frontend/components/SubscriptionStatus.tsx +135 -135
- package/sails/stripe/files/frontend/hooks/useSubscription.ts +86 -86
- package/sails/stripe/files/frontend/pages/Checkout.tsx +116 -116
- package/sails/stripe/files/frontend/pages/Pricing.tsx +226 -226
- package/sails/stripe/install.ts +378 -378
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
import { Link } from "react-router";
|
|
2
|
-
|
|
3
|
-
export interface ConsentState {
|
|
4
|
-
privacyPolicy: boolean;
|
|
5
|
-
termsOfService: boolean;
|
|
6
|
-
marketingEmails: boolean;
|
|
7
|
-
analytics: boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface ConsentCheckboxesProps {
|
|
11
|
-
value: ConsentState;
|
|
12
|
-
onChange: (value: ConsentState) => void;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default function ConsentCheckboxes({
|
|
16
|
-
value,
|
|
17
|
-
onChange,
|
|
18
|
-
}: ConsentCheckboxesProps) {
|
|
19
|
-
const update = (field: keyof ConsentState, checked: boolean) => {
|
|
20
|
-
onChange({ ...value, [field]: checked });
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<div className="space-y-3">
|
|
25
|
-
<p className="text-xs font-medium text-keel-gray-400 uppercase tracking-wide">
|
|
26
|
-
Consent
|
|
27
|
-
</p>
|
|
28
|
-
|
|
29
|
-
<label className="flex items-start gap-3 cursor-pointer">
|
|
30
|
-
<input
|
|
31
|
-
type="checkbox"
|
|
32
|
-
checked={value.privacyPolicy}
|
|
33
|
-
onChange={(e) => update("privacyPolicy", e.target.checked)}
|
|
34
|
-
className="mt-0.5 h-4 w-4 rounded border-keel-gray-800 bg-keel-gray-900 text-keel-blue focus:ring-keel-blue"
|
|
35
|
-
/>
|
|
36
|
-
<span className="text-sm text-keel-gray-100">
|
|
37
|
-
I have read and accept the{" "}
|
|
38
|
-
<Link
|
|
39
|
-
to="/privacy-policy"
|
|
40
|
-
target="_blank"
|
|
41
|
-
className="font-medium text-keel-blue hover:text-keel-blue/80"
|
|
42
|
-
>
|
|
43
|
-
Privacy Policy
|
|
44
|
-
</Link>
|
|
45
|
-
<span className="text-red-400"> *</span>
|
|
46
|
-
</span>
|
|
47
|
-
</label>
|
|
48
|
-
|
|
49
|
-
<label className="flex items-start gap-3 cursor-pointer">
|
|
50
|
-
<input
|
|
51
|
-
type="checkbox"
|
|
52
|
-
checked={value.termsOfService}
|
|
53
|
-
onChange={(e) => update("termsOfService", e.target.checked)}
|
|
54
|
-
className="mt-0.5 h-4 w-4 rounded border-keel-gray-800 bg-keel-gray-900 text-keel-blue focus:ring-keel-blue"
|
|
55
|
-
/>
|
|
56
|
-
<span className="text-sm text-keel-gray-100">
|
|
57
|
-
I agree to the{" "}
|
|
58
|
-
<a
|
|
59
|
-
href="#"
|
|
60
|
-
target="_blank"
|
|
61
|
-
rel="noopener noreferrer"
|
|
62
|
-
className="font-medium text-keel-blue hover:text-keel-blue/80"
|
|
63
|
-
>
|
|
64
|
-
Terms of Service
|
|
65
|
-
</a>
|
|
66
|
-
<span className="text-red-400"> *</span>
|
|
67
|
-
</span>
|
|
68
|
-
</label>
|
|
69
|
-
|
|
70
|
-
<label className="flex items-start gap-3 cursor-pointer">
|
|
71
|
-
<input
|
|
72
|
-
type="checkbox"
|
|
73
|
-
checked={value.marketingEmails}
|
|
74
|
-
onChange={(e) => update("marketingEmails", e.target.checked)}
|
|
75
|
-
className="mt-0.5 h-4 w-4 rounded border-keel-gray-800 bg-keel-gray-900 text-keel-blue focus:ring-keel-blue"
|
|
76
|
-
/>
|
|
77
|
-
<span className="text-sm text-keel-gray-400">
|
|
78
|
-
I would like to receive product updates and marketing emails
|
|
79
|
-
<span className="ml-1 text-xs text-keel-gray-400/60">(optional)</span>
|
|
80
|
-
</span>
|
|
81
|
-
</label>
|
|
82
|
-
|
|
83
|
-
<label className="flex items-start gap-3 cursor-pointer">
|
|
84
|
-
<input
|
|
85
|
-
type="checkbox"
|
|
86
|
-
checked={value.analytics}
|
|
87
|
-
onChange={(e) => update("analytics", e.target.checked)}
|
|
88
|
-
className="mt-0.5 h-4 w-4 rounded border-keel-gray-800 bg-keel-gray-900 text-keel-blue focus:ring-keel-blue"
|
|
89
|
-
/>
|
|
90
|
-
<span className="text-sm text-keel-gray-400">
|
|
91
|
-
I consent to anonymous usage analytics to help improve the service
|
|
92
|
-
<span className="ml-1 text-xs text-keel-gray-400/60">(optional)</span>
|
|
93
|
-
</span>
|
|
94
|
-
</label>
|
|
95
|
-
</div>
|
|
96
|
-
);
|
|
97
|
-
}
|
|
1
|
+
import { Link } from "react-router";
|
|
2
|
+
|
|
3
|
+
export interface ConsentState {
|
|
4
|
+
privacyPolicy: boolean;
|
|
5
|
+
termsOfService: boolean;
|
|
6
|
+
marketingEmails: boolean;
|
|
7
|
+
analytics: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface ConsentCheckboxesProps {
|
|
11
|
+
value: ConsentState;
|
|
12
|
+
onChange: (value: ConsentState) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default function ConsentCheckboxes({
|
|
16
|
+
value,
|
|
17
|
+
onChange,
|
|
18
|
+
}: ConsentCheckboxesProps) {
|
|
19
|
+
const update = (field: keyof ConsentState, checked: boolean) => {
|
|
20
|
+
onChange({ ...value, [field]: checked });
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div className="space-y-3">
|
|
25
|
+
<p className="text-xs font-medium text-keel-gray-400 uppercase tracking-wide">
|
|
26
|
+
Consent
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
<label className="flex items-start gap-3 cursor-pointer">
|
|
30
|
+
<input
|
|
31
|
+
type="checkbox"
|
|
32
|
+
checked={value.privacyPolicy}
|
|
33
|
+
onChange={(e) => update("privacyPolicy", e.target.checked)}
|
|
34
|
+
className="mt-0.5 h-4 w-4 rounded border-keel-gray-800 bg-keel-gray-900 text-keel-blue focus:ring-keel-blue"
|
|
35
|
+
/>
|
|
36
|
+
<span className="text-sm text-keel-gray-100">
|
|
37
|
+
I have read and accept the{" "}
|
|
38
|
+
<Link
|
|
39
|
+
to="/privacy-policy"
|
|
40
|
+
target="_blank"
|
|
41
|
+
className="font-medium text-keel-blue hover:text-keel-blue/80"
|
|
42
|
+
>
|
|
43
|
+
Privacy Policy
|
|
44
|
+
</Link>
|
|
45
|
+
<span className="text-red-400"> *</span>
|
|
46
|
+
</span>
|
|
47
|
+
</label>
|
|
48
|
+
|
|
49
|
+
<label className="flex items-start gap-3 cursor-pointer">
|
|
50
|
+
<input
|
|
51
|
+
type="checkbox"
|
|
52
|
+
checked={value.termsOfService}
|
|
53
|
+
onChange={(e) => update("termsOfService", e.target.checked)}
|
|
54
|
+
className="mt-0.5 h-4 w-4 rounded border-keel-gray-800 bg-keel-gray-900 text-keel-blue focus:ring-keel-blue"
|
|
55
|
+
/>
|
|
56
|
+
<span className="text-sm text-keel-gray-100">
|
|
57
|
+
I agree to the{" "}
|
|
58
|
+
<a
|
|
59
|
+
href="#"
|
|
60
|
+
target="_blank"
|
|
61
|
+
rel="noopener noreferrer"
|
|
62
|
+
className="font-medium text-keel-blue hover:text-keel-blue/80"
|
|
63
|
+
>
|
|
64
|
+
Terms of Service
|
|
65
|
+
</a>
|
|
66
|
+
<span className="text-red-400"> *</span>
|
|
67
|
+
</span>
|
|
68
|
+
</label>
|
|
69
|
+
|
|
70
|
+
<label className="flex items-start gap-3 cursor-pointer">
|
|
71
|
+
<input
|
|
72
|
+
type="checkbox"
|
|
73
|
+
checked={value.marketingEmails}
|
|
74
|
+
onChange={(e) => update("marketingEmails", e.target.checked)}
|
|
75
|
+
className="mt-0.5 h-4 w-4 rounded border-keel-gray-800 bg-keel-gray-900 text-keel-blue focus:ring-keel-blue"
|
|
76
|
+
/>
|
|
77
|
+
<span className="text-sm text-keel-gray-400">
|
|
78
|
+
I would like to receive product updates and marketing emails
|
|
79
|
+
<span className="ml-1 text-xs text-keel-gray-400/60">(optional)</span>
|
|
80
|
+
</span>
|
|
81
|
+
</label>
|
|
82
|
+
|
|
83
|
+
<label className="flex items-start gap-3 cursor-pointer">
|
|
84
|
+
<input
|
|
85
|
+
type="checkbox"
|
|
86
|
+
checked={value.analytics}
|
|
87
|
+
onChange={(e) => update("analytics", e.target.checked)}
|
|
88
|
+
className="mt-0.5 h-4 w-4 rounded border-keel-gray-800 bg-keel-gray-900 text-keel-blue focus:ring-keel-blue"
|
|
89
|
+
/>
|
|
90
|
+
<span className="text-sm text-keel-gray-400">
|
|
91
|
+
I consent to anonymous usage analytics to help improve the service
|
|
92
|
+
<span className="ml-1 text-xs text-keel-gray-400/60">(optional)</span>
|
|
93
|
+
</span>
|
|
94
|
+
</label>
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
@@ -1,192 +1,192 @@
|
|
|
1
|
-
import { useState, useEffect } from "react";
|
|
2
|
-
import { apiGet, apiPost, apiDelete } from "@/lib/api";
|
|
3
|
-
|
|
4
|
-
interface DeletionStatus {
|
|
5
|
-
pending: boolean;
|
|
6
|
-
scheduledAt?: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export default function AccountDeletionRequest() {
|
|
10
|
-
const [deletionStatus, setDeletionStatus] = useState<DeletionStatus>({
|
|
11
|
-
pending: false,
|
|
12
|
-
});
|
|
13
|
-
const [reason, setReason] = useState("");
|
|
14
|
-
const [showConfirm, setShowConfirm] = useState(false);
|
|
15
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
16
|
-
const [error, setError] = useState("");
|
|
17
|
-
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
async function checkStatus() {
|
|
20
|
-
try {
|
|
21
|
-
const status = await apiGet<DeletionStatus>(
|
|
22
|
-
"/api/gdpr/deletion-status",
|
|
23
|
-
);
|
|
24
|
-
setDeletionStatus(status);
|
|
25
|
-
} catch {
|
|
26
|
-
// No pending deletion
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
checkStatus();
|
|
30
|
-
}, []);
|
|
31
|
-
|
|
32
|
-
const handleRequestDeletion = async () => {
|
|
33
|
-
setIsLoading(true);
|
|
34
|
-
setError("");
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
const status = await apiPost<DeletionStatus>("/api/gdpr/delete-account", {
|
|
38
|
-
reason: reason || undefined,
|
|
39
|
-
});
|
|
40
|
-
setDeletionStatus(status);
|
|
41
|
-
setShowConfirm(false);
|
|
42
|
-
} catch (err) {
|
|
43
|
-
setError(
|
|
44
|
-
err instanceof Error ? err.message : "Failed to request deletion.",
|
|
45
|
-
);
|
|
46
|
-
} finally {
|
|
47
|
-
setIsLoading(false);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const handleCancelDeletion = async () => {
|
|
52
|
-
setIsLoading(true);
|
|
53
|
-
setError("");
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
await apiDelete("/api/gdpr/delete-account");
|
|
57
|
-
setDeletionStatus({ pending: false });
|
|
58
|
-
} catch (err) {
|
|
59
|
-
setError(
|
|
60
|
-
err instanceof Error
|
|
61
|
-
? err.message
|
|
62
|
-
: "Failed to cancel deletion request.",
|
|
63
|
-
);
|
|
64
|
-
} finally {
|
|
65
|
-
setIsLoading(false);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
if (deletionStatus.pending) {
|
|
70
|
-
const scheduledDate = deletionStatus.scheduledAt
|
|
71
|
-
? new Date(deletionStatus.scheduledAt).toLocaleDateString("en-US", {
|
|
72
|
-
year: "numeric",
|
|
73
|
-
month: "long",
|
|
74
|
-
day: "numeric",
|
|
75
|
-
})
|
|
76
|
-
: "30 days from now";
|
|
77
|
-
|
|
78
|
-
return (
|
|
79
|
-
<div>
|
|
80
|
-
<div className="rounded-lg border border-amber-500/30 bg-amber-500/10 p-4">
|
|
81
|
-
<div className="flex items-start gap-3">
|
|
82
|
-
<svg
|
|
83
|
-
className="mt-0.5 h-5 w-5 shrink-0 text-amber-400"
|
|
84
|
-
fill="none"
|
|
85
|
-
viewBox="0 0 24 24"
|
|
86
|
-
stroke="currentColor"
|
|
87
|
-
>
|
|
88
|
-
<path
|
|
89
|
-
strokeLinecap="round"
|
|
90
|
-
strokeLinejoin="round"
|
|
91
|
-
strokeWidth={2}
|
|
92
|
-
d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z"
|
|
93
|
-
/>
|
|
94
|
-
</svg>
|
|
95
|
-
<div>
|
|
96
|
-
<p className="text-sm font-medium text-amber-400">
|
|
97
|
-
Account deletion scheduled
|
|
98
|
-
</p>
|
|
99
|
-
<p className="mt-1 text-xs text-amber-400/80">
|
|
100
|
-
Your account is scheduled for deletion on{" "}
|
|
101
|
-
<span className="font-medium">{scheduledDate}</span>. You can
|
|
102
|
-
cancel this request before that date.
|
|
103
|
-
</p>
|
|
104
|
-
</div>
|
|
105
|
-
</div>
|
|
106
|
-
<button
|
|
107
|
-
onClick={handleCancelDeletion}
|
|
108
|
-
disabled={isLoading}
|
|
109
|
-
className="mt-3 rounded-lg border border-amber-500/30 px-4 py-2 text-sm font-medium text-amber-400 transition-colors hover:bg-amber-500/10 disabled:opacity-50"
|
|
110
|
-
>
|
|
111
|
-
{isLoading ? "Cancelling..." : "Cancel deletion"}
|
|
112
|
-
</button>
|
|
113
|
-
</div>
|
|
114
|
-
{error && <p className="mt-2 text-xs text-red-400">{error}</p>}
|
|
115
|
-
</div>
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return (
|
|
120
|
-
<div>
|
|
121
|
-
{!showConfirm ? (
|
|
122
|
-
<button
|
|
123
|
-
onClick={() => setShowConfirm(true)}
|
|
124
|
-
className="inline-flex items-center rounded-lg text-sm font-medium text-red-400 transition-colors hover:bg-red-500/10 px-4 py-2"
|
|
125
|
-
>
|
|
126
|
-
<svg
|
|
127
|
-
className="mr-2 h-4 w-4"
|
|
128
|
-
fill="none"
|
|
129
|
-
viewBox="0 0 24 24"
|
|
130
|
-
stroke="currentColor"
|
|
131
|
-
>
|
|
132
|
-
<path
|
|
133
|
-
strokeLinecap="round"
|
|
134
|
-
strokeLinejoin="round"
|
|
135
|
-
strokeWidth={2}
|
|
136
|
-
d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"
|
|
137
|
-
/>
|
|
138
|
-
</svg>
|
|
139
|
-
Delete my account
|
|
140
|
-
</button>
|
|
141
|
-
) : (
|
|
142
|
-
<div className="rounded-lg border border-red-500/30 bg-red-500/10 p-4">
|
|
143
|
-
<h4 className="text-sm font-medium text-red-400">
|
|
144
|
-
Are you sure you want to delete your account?
|
|
145
|
-
</h4>
|
|
146
|
-
<p className="mt-1 text-xs text-red-400/80">
|
|
147
|
-
This action will schedule your account for permanent deletion. You
|
|
148
|
-
will have a 30-day grace period to cancel the request. After that,
|
|
149
|
-
all your data will be permanently removed.
|
|
150
|
-
</p>
|
|
151
|
-
|
|
152
|
-
<div className="mt-3">
|
|
153
|
-
<label
|
|
154
|
-
htmlFor="deletionReason"
|
|
155
|
-
className="mb-1.5 block text-xs font-medium text-red-400"
|
|
156
|
-
>
|
|
157
|
-
Reason for leaving (optional)
|
|
158
|
-
</label>
|
|
159
|
-
<textarea
|
|
160
|
-
id="deletionReason"
|
|
161
|
-
value={reason}
|
|
162
|
-
onChange={(e) => setReason(e.target.value)}
|
|
163
|
-
rows={2}
|
|
164
|
-
placeholder="We'd appreciate knowing why you're leaving..."
|
|
165
|
-
className="w-full rounded-lg border border-keel-gray-800 bg-keel-gray-900 px-3 py-2 text-sm text-white placeholder-keel-gray-400 focus:border-red-400 focus:outline-none focus:ring-2 focus:ring-red-400/20"
|
|
166
|
-
/>
|
|
167
|
-
</div>
|
|
168
|
-
|
|
169
|
-
<div className="mt-3 flex gap-3">
|
|
170
|
-
<button
|
|
171
|
-
onClick={handleRequestDeletion}
|
|
172
|
-
disabled={isLoading}
|
|
173
|
-
className="rounded-lg bg-red-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-red-700 disabled:opacity-50"
|
|
174
|
-
>
|
|
175
|
-
{isLoading ? "Processing..." : "Yes, delete my account"}
|
|
176
|
-
</button>
|
|
177
|
-
<button
|
|
178
|
-
onClick={() => {
|
|
179
|
-
setShowConfirm(false);
|
|
180
|
-
setReason("");
|
|
181
|
-
}}
|
|
182
|
-
className="rounded-lg border border-keel-gray-800 px-4 py-2 text-sm font-medium text-keel-gray-100 transition-colors hover:border-keel-gray-400"
|
|
183
|
-
>
|
|
184
|
-
Cancel
|
|
185
|
-
</button>
|
|
186
|
-
</div>
|
|
187
|
-
</div>
|
|
188
|
-
)}
|
|
189
|
-
{error && <p className="mt-2 text-xs text-red-400">{error}</p>}
|
|
190
|
-
</div>
|
|
191
|
-
);
|
|
192
|
-
}
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
import { apiGet, apiPost, apiDelete } from "@/lib/api";
|
|
3
|
+
|
|
4
|
+
interface DeletionStatus {
|
|
5
|
+
pending: boolean;
|
|
6
|
+
scheduledAt?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default function AccountDeletionRequest() {
|
|
10
|
+
const [deletionStatus, setDeletionStatus] = useState<DeletionStatus>({
|
|
11
|
+
pending: false,
|
|
12
|
+
});
|
|
13
|
+
const [reason, setReason] = useState("");
|
|
14
|
+
const [showConfirm, setShowConfirm] = useState(false);
|
|
15
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
16
|
+
const [error, setError] = useState("");
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
async function checkStatus() {
|
|
20
|
+
try {
|
|
21
|
+
const status = await apiGet<DeletionStatus>(
|
|
22
|
+
"/api/gdpr/deletion-status",
|
|
23
|
+
);
|
|
24
|
+
setDeletionStatus(status);
|
|
25
|
+
} catch {
|
|
26
|
+
// No pending deletion
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
checkStatus();
|
|
30
|
+
}, []);
|
|
31
|
+
|
|
32
|
+
const handleRequestDeletion = async () => {
|
|
33
|
+
setIsLoading(true);
|
|
34
|
+
setError("");
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const status = await apiPost<DeletionStatus>("/api/gdpr/delete-account", {
|
|
38
|
+
reason: reason || undefined,
|
|
39
|
+
});
|
|
40
|
+
setDeletionStatus(status);
|
|
41
|
+
setShowConfirm(false);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
setError(
|
|
44
|
+
err instanceof Error ? err.message : "Failed to request deletion.",
|
|
45
|
+
);
|
|
46
|
+
} finally {
|
|
47
|
+
setIsLoading(false);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const handleCancelDeletion = async () => {
|
|
52
|
+
setIsLoading(true);
|
|
53
|
+
setError("");
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
await apiDelete("/api/gdpr/delete-account");
|
|
57
|
+
setDeletionStatus({ pending: false });
|
|
58
|
+
} catch (err) {
|
|
59
|
+
setError(
|
|
60
|
+
err instanceof Error
|
|
61
|
+
? err.message
|
|
62
|
+
: "Failed to cancel deletion request.",
|
|
63
|
+
);
|
|
64
|
+
} finally {
|
|
65
|
+
setIsLoading(false);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
if (deletionStatus.pending) {
|
|
70
|
+
const scheduledDate = deletionStatus.scheduledAt
|
|
71
|
+
? new Date(deletionStatus.scheduledAt).toLocaleDateString("en-US", {
|
|
72
|
+
year: "numeric",
|
|
73
|
+
month: "long",
|
|
74
|
+
day: "numeric",
|
|
75
|
+
})
|
|
76
|
+
: "30 days from now";
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div>
|
|
80
|
+
<div className="rounded-lg border border-amber-500/30 bg-amber-500/10 p-4">
|
|
81
|
+
<div className="flex items-start gap-3">
|
|
82
|
+
<svg
|
|
83
|
+
className="mt-0.5 h-5 w-5 shrink-0 text-amber-400"
|
|
84
|
+
fill="none"
|
|
85
|
+
viewBox="0 0 24 24"
|
|
86
|
+
stroke="currentColor"
|
|
87
|
+
>
|
|
88
|
+
<path
|
|
89
|
+
strokeLinecap="round"
|
|
90
|
+
strokeLinejoin="round"
|
|
91
|
+
strokeWidth={2}
|
|
92
|
+
d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z"
|
|
93
|
+
/>
|
|
94
|
+
</svg>
|
|
95
|
+
<div>
|
|
96
|
+
<p className="text-sm font-medium text-amber-400">
|
|
97
|
+
Account deletion scheduled
|
|
98
|
+
</p>
|
|
99
|
+
<p className="mt-1 text-xs text-amber-400/80">
|
|
100
|
+
Your account is scheduled for deletion on{" "}
|
|
101
|
+
<span className="font-medium">{scheduledDate}</span>. You can
|
|
102
|
+
cancel this request before that date.
|
|
103
|
+
</p>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
<button
|
|
107
|
+
onClick={handleCancelDeletion}
|
|
108
|
+
disabled={isLoading}
|
|
109
|
+
className="mt-3 rounded-lg border border-amber-500/30 px-4 py-2 text-sm font-medium text-amber-400 transition-colors hover:bg-amber-500/10 disabled:opacity-50"
|
|
110
|
+
>
|
|
111
|
+
{isLoading ? "Cancelling..." : "Cancel deletion"}
|
|
112
|
+
</button>
|
|
113
|
+
</div>
|
|
114
|
+
{error && <p className="mt-2 text-xs text-red-400">{error}</p>}
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<div>
|
|
121
|
+
{!showConfirm ? (
|
|
122
|
+
<button
|
|
123
|
+
onClick={() => setShowConfirm(true)}
|
|
124
|
+
className="inline-flex items-center rounded-lg text-sm font-medium text-red-400 transition-colors hover:bg-red-500/10 px-4 py-2"
|
|
125
|
+
>
|
|
126
|
+
<svg
|
|
127
|
+
className="mr-2 h-4 w-4"
|
|
128
|
+
fill="none"
|
|
129
|
+
viewBox="0 0 24 24"
|
|
130
|
+
stroke="currentColor"
|
|
131
|
+
>
|
|
132
|
+
<path
|
|
133
|
+
strokeLinecap="round"
|
|
134
|
+
strokeLinejoin="round"
|
|
135
|
+
strokeWidth={2}
|
|
136
|
+
d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"
|
|
137
|
+
/>
|
|
138
|
+
</svg>
|
|
139
|
+
Delete my account
|
|
140
|
+
</button>
|
|
141
|
+
) : (
|
|
142
|
+
<div className="rounded-lg border border-red-500/30 bg-red-500/10 p-4">
|
|
143
|
+
<h4 className="text-sm font-medium text-red-400">
|
|
144
|
+
Are you sure you want to delete your account?
|
|
145
|
+
</h4>
|
|
146
|
+
<p className="mt-1 text-xs text-red-400/80">
|
|
147
|
+
This action will schedule your account for permanent deletion. You
|
|
148
|
+
will have a 30-day grace period to cancel the request. After that,
|
|
149
|
+
all your data will be permanently removed.
|
|
150
|
+
</p>
|
|
151
|
+
|
|
152
|
+
<div className="mt-3">
|
|
153
|
+
<label
|
|
154
|
+
htmlFor="deletionReason"
|
|
155
|
+
className="mb-1.5 block text-xs font-medium text-red-400"
|
|
156
|
+
>
|
|
157
|
+
Reason for leaving (optional)
|
|
158
|
+
</label>
|
|
159
|
+
<textarea
|
|
160
|
+
id="deletionReason"
|
|
161
|
+
value={reason}
|
|
162
|
+
onChange={(e) => setReason(e.target.value)}
|
|
163
|
+
rows={2}
|
|
164
|
+
placeholder="We'd appreciate knowing why you're leaving..."
|
|
165
|
+
className="w-full rounded-lg border border-keel-gray-800 bg-keel-gray-900 px-3 py-2 text-sm text-white placeholder-keel-gray-400 focus:border-red-400 focus:outline-none focus:ring-2 focus:ring-red-400/20"
|
|
166
|
+
/>
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
<div className="mt-3 flex gap-3">
|
|
170
|
+
<button
|
|
171
|
+
onClick={handleRequestDeletion}
|
|
172
|
+
disabled={isLoading}
|
|
173
|
+
className="rounded-lg bg-red-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-red-700 disabled:opacity-50"
|
|
174
|
+
>
|
|
175
|
+
{isLoading ? "Processing..." : "Yes, delete my account"}
|
|
176
|
+
</button>
|
|
177
|
+
<button
|
|
178
|
+
onClick={() => {
|
|
179
|
+
setShowConfirm(false);
|
|
180
|
+
setReason("");
|
|
181
|
+
}}
|
|
182
|
+
className="rounded-lg border border-keel-gray-800 px-4 py-2 text-sm font-medium text-keel-gray-100 transition-colors hover:border-keel-gray-400"
|
|
183
|
+
>
|
|
184
|
+
Cancel
|
|
185
|
+
</button>
|
|
186
|
+
</div>
|
|
187
|
+
</div>
|
|
188
|
+
)}
|
|
189
|
+
{error && <p className="mt-2 text-xs text-red-400">{error}</p>}
|
|
190
|
+
</div>
|
|
191
|
+
);
|
|
192
|
+
}
|