@ampless/admin 0.2.0-alpha.10 → 0.2.0-alpha.12

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.
@@ -31,12 +31,8 @@ function createMedia(outputs, cmsConfig) {
31
31
  return { publicMediaUrl: urlFor };
32
32
  }
33
33
 
34
- // src/lib/admin-site-cookie.ts
35
- var ADMIN_SITE_COOKIE = "admin-site-id";
36
-
37
34
  export {
38
35
  setAdminMediaContext,
39
36
  publicMediaUrl,
40
- createMedia,
41
- ADMIN_SITE_COOKIE
37
+ createMedia
42
38
  };
@@ -0,0 +1,48 @@
1
+ 'use client';
2
+ import {
3
+ useT
4
+ } from "./chunk-OFHKZNZS.js";
5
+
6
+ // src/components/admin-dashboard.tsx
7
+ import { useEffect, useState } from "react";
8
+ import Link from "next/link";
9
+ import { listPosts } from "ampless";
10
+ import { Button, Card, CardContent, CardHeader, CardTitle } from "@ampless/runtime/ui";
11
+ import { jsx, jsxs } from "react/jsx-runtime";
12
+ function AdminDashboard() {
13
+ const t = useT();
14
+ const [posts, setPosts] = useState([]);
15
+ const [loading, setLoading] = useState(true);
16
+ useEffect(() => {
17
+ listPosts({ status: "all" }).then(setPosts).finally(() => setLoading(false));
18
+ }, []);
19
+ const published = posts.filter((p) => p.status === "published").length;
20
+ const drafts = posts.filter((p) => p.status === "draft").length;
21
+ return /* @__PURE__ */ jsxs("div", { className: "mx-auto max-w-7xl p-4 md:p-8", children: [
22
+ /* @__PURE__ */ jsxs("div", { className: "mb-6 flex flex-wrap items-center justify-between gap-3 md:mb-8", children: [
23
+ /* @__PURE__ */ jsx("h1", { className: "text-2xl font-bold md:text-3xl", children: t("dashboard.title") }),
24
+ /* @__PURE__ */ jsx(Button, { asChild: true, children: /* @__PURE__ */ jsx(Link, { href: "/admin/posts/new", children: t("dashboard.newPost") }) })
25
+ ] }),
26
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3", children: [
27
+ /* @__PURE__ */ jsxs(Card, { children: [
28
+ /* @__PURE__ */ jsx(CardHeader, { children: /* @__PURE__ */ jsx(CardTitle, { children: t("dashboard.totalPosts") }) }),
29
+ /* @__PURE__ */ jsxs(CardContent, { children: [
30
+ /* @__PURE__ */ jsx("p", { className: "text-3xl font-bold", children: loading ? "\u2014" : posts.length }),
31
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("dashboard.totalLabel") })
32
+ ] })
33
+ ] }),
34
+ /* @__PURE__ */ jsxs(Card, { children: [
35
+ /* @__PURE__ */ jsx(CardHeader, { children: /* @__PURE__ */ jsx(CardTitle, { children: t("dashboard.published") }) }),
36
+ /* @__PURE__ */ jsx(CardContent, { children: /* @__PURE__ */ jsx("p", { className: "text-3xl font-bold", children: loading ? "\u2014" : published }) })
37
+ ] }),
38
+ /* @__PURE__ */ jsxs(Card, { children: [
39
+ /* @__PURE__ */ jsx(CardHeader, { children: /* @__PURE__ */ jsx(CardTitle, { children: t("dashboard.drafts") }) }),
40
+ /* @__PURE__ */ jsx(CardContent, { children: /* @__PURE__ */ jsx("p", { className: "text-3xl font-bold", children: loading ? "\u2014" : drafts }) })
41
+ ] })
42
+ ] })
43
+ ] });
44
+ }
45
+
46
+ export {
47
+ AdminDashboard
48
+ };
@@ -0,0 +1,198 @@
1
+ 'use client';
2
+ import {
3
+ useT
4
+ } from "./chunk-OFHKZNZS.js";
5
+
6
+ // src/components/login-view.tsx
7
+ import { useState } from "react";
8
+ import { useRouter } from "next/navigation";
9
+ import {
10
+ signIn,
11
+ signUp,
12
+ confirmSignUp,
13
+ resetPassword,
14
+ confirmResetPassword
15
+ } from "aws-amplify/auth";
16
+ import {
17
+ Button,
18
+ Input,
19
+ Label,
20
+ Card,
21
+ CardContent,
22
+ CardHeader,
23
+ CardTitle,
24
+ CardDescription
25
+ } from "@ampless/runtime/ui";
26
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
27
+ function LoginPage() {
28
+ const router = useRouter();
29
+ const t = useT();
30
+ const [mode, setMode] = useState("signIn");
31
+ const [email, setEmail] = useState("");
32
+ const [password, setPassword] = useState("");
33
+ const [code, setCode] = useState("");
34
+ const [error, setError] = useState(null);
35
+ const [info, setInfo] = useState(null);
36
+ const [loading, setLoading] = useState(false);
37
+ function go(next) {
38
+ setMode(next);
39
+ setError(null);
40
+ setInfo(null);
41
+ setCode("");
42
+ if (next === "signIn" || next === "signUp" || next === "forgot") setPassword("");
43
+ }
44
+ async function handleSubmit(e) {
45
+ e.preventDefault();
46
+ setError(null);
47
+ setInfo(null);
48
+ setLoading(true);
49
+ try {
50
+ if (mode === "signIn") {
51
+ const result = await signIn({ username: email, password });
52
+ if (result.isSignedIn) {
53
+ router.push("/admin");
54
+ router.refresh();
55
+ } else {
56
+ setError(t("auth.additionalStep", { step: result.nextStep.signInStep }));
57
+ }
58
+ } else if (mode === "signUp") {
59
+ await signUp({
60
+ username: email,
61
+ password,
62
+ options: { userAttributes: { email } }
63
+ });
64
+ go("confirm");
65
+ } else if (mode === "confirm") {
66
+ await confirmSignUp({ username: email, confirmationCode: code });
67
+ const result = await signIn({ username: email, password });
68
+ if (result.isSignedIn) {
69
+ router.push("/admin");
70
+ router.refresh();
71
+ }
72
+ } else if (mode === "forgot") {
73
+ await resetPassword({ username: email });
74
+ setMode("reset");
75
+ setInfo(t("auth.forgot.codeSent"));
76
+ } else if (mode === "reset") {
77
+ await confirmResetPassword({
78
+ username: email,
79
+ confirmationCode: code,
80
+ newPassword: password
81
+ });
82
+ const result = await signIn({ username: email, password });
83
+ if (result.isSignedIn) {
84
+ router.push("/admin");
85
+ router.refresh();
86
+ } else {
87
+ setMode("signIn");
88
+ setInfo(t("auth.reset.passwordUpdated"));
89
+ }
90
+ }
91
+ } catch (err) {
92
+ setError(err instanceof Error ? err.message : String(err));
93
+ } finally {
94
+ setLoading(false);
95
+ }
96
+ }
97
+ const showEmail = mode !== "confirm" && mode !== "reset";
98
+ const showPassword = mode === "signIn" || mode === "signUp" || mode === "reset";
99
+ const showCode = mode === "confirm" || mode === "reset";
100
+ return /* @__PURE__ */ jsx("main", { className: "flex min-h-screen items-center justify-center bg-muted/30 p-4", children: /* @__PURE__ */ jsxs(Card, { className: "w-full max-w-md", children: [
101
+ /* @__PURE__ */ jsxs(CardHeader, { children: [
102
+ /* @__PURE__ */ jsx(CardTitle, { children: t(`auth.${mode}.title`) }),
103
+ /* @__PURE__ */ jsx(CardDescription, { children: t(`auth.${mode}.description`) })
104
+ ] }),
105
+ /* @__PURE__ */ jsx(CardContent, { children: /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, className: "space-y-4", children: [
106
+ showEmail && /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
107
+ /* @__PURE__ */ jsx(Label, { htmlFor: "email", children: t("auth.common.email") }),
108
+ /* @__PURE__ */ jsx(
109
+ Input,
110
+ {
111
+ id: "email",
112
+ type: "email",
113
+ required: true,
114
+ value: email,
115
+ onChange: (e) => setEmail(e.target.value),
116
+ autoComplete: "email"
117
+ }
118
+ )
119
+ ] }),
120
+ showCode && /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
121
+ /* @__PURE__ */ jsx(Label, { htmlFor: "code", children: t("auth.common.code") }),
122
+ /* @__PURE__ */ jsx(
123
+ Input,
124
+ {
125
+ id: "code",
126
+ required: true,
127
+ value: code,
128
+ onChange: (e) => setCode(e.target.value),
129
+ autoComplete: "one-time-code"
130
+ }
131
+ )
132
+ ] }),
133
+ showPassword && /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
134
+ /* @__PURE__ */ jsx(Label, { htmlFor: "password", children: mode === "reset" ? t("auth.common.newPassword") : t("auth.common.password") }),
135
+ /* @__PURE__ */ jsx(
136
+ Input,
137
+ {
138
+ id: "password",
139
+ type: "password",
140
+ required: true,
141
+ minLength: 8,
142
+ value: password,
143
+ onChange: (e) => setPassword(e.target.value),
144
+ autoComplete: mode === "signIn" ? "current-password" : "new-password"
145
+ }
146
+ ),
147
+ (mode === "signUp" || mode === "reset") && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t("auth.common.passwordHint") })
148
+ ] }),
149
+ info && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: info }),
150
+ error && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: error }),
151
+ /* @__PURE__ */ jsx(Button, { type: "submit", className: "w-full", disabled: loading, children: loading ? t("auth.common.working") : t(`auth.${mode}.submit`) }),
152
+ /* @__PURE__ */ jsxs("div", { className: "space-y-1 text-center text-sm", children: [
153
+ mode === "signIn" && /* @__PURE__ */ jsxs(Fragment, { children: [
154
+ /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx(
155
+ "button",
156
+ {
157
+ type: "button",
158
+ className: "text-primary hover:underline",
159
+ onClick: () => go("forgot"),
160
+ children: t("auth.signIn.forgotPassword")
161
+ }
162
+ ) }),
163
+ /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx(
164
+ "button",
165
+ {
166
+ type: "button",
167
+ className: "text-primary hover:underline",
168
+ onClick: () => go("signUp"),
169
+ children: t("auth.signIn.createAccount")
170
+ }
171
+ ) })
172
+ ] }),
173
+ (mode === "signUp" || mode === "forgot" || mode === "reset") && /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx(
174
+ "button",
175
+ {
176
+ type: "button",
177
+ className: "text-primary hover:underline",
178
+ onClick: () => go("signIn"),
179
+ children: t("auth.signUp.backToSignIn")
180
+ }
181
+ ) }),
182
+ mode === "reset" && /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx(
183
+ "button",
184
+ {
185
+ type: "button",
186
+ className: "text-primary hover:underline",
187
+ onClick: () => go("forgot"),
188
+ children: t("auth.reset.resendCode")
189
+ }
190
+ ) })
191
+ ] })
192
+ ] }) })
193
+ ] }) });
194
+ }
195
+
196
+ export {
197
+ LoginPage
198
+ };