nextworks 0.1.0-alpha.13 → 0.1.0-alpha.14
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/README.md +20 -9
- package/dist/kits/auth-core/.nextworks/docs/AUTH_CORE_README.md +2 -2
- package/dist/kits/auth-core/.nextworks/docs/AUTH_QUICKSTART.md +264 -244
- package/dist/kits/auth-core/app/(protected)/settings/profile/profile-form.tsx +120 -114
- package/dist/kits/auth-core/app/api/auth/forgot-password/route.ts +116 -114
- package/dist/kits/auth-core/app/api/auth/reset-password/route.ts +66 -63
- package/dist/kits/auth-core/app/api/auth/send-verify-email/route.ts +1 -1
- package/dist/kits/auth-core/app/api/users/[id]/route.ts +134 -127
- package/dist/kits/auth-core/app/auth/reset-password/page.tsx +186 -187
- package/dist/kits/auth-core/components/auth/dashboard.tsx +25 -2
- package/dist/kits/auth-core/components/auth/forgot-password-form.tsx +90 -90
- package/dist/kits/auth-core/components/auth/login-form.tsx +492 -467
- package/dist/kits/auth-core/components/auth/signup-form.tsx +28 -29
- package/dist/kits/auth-core/lib/auth.ts +46 -15
- package/dist/kits/auth-core/lib/forms/map-errors.ts +37 -11
- package/dist/kits/auth-core/lib/server/result.ts +45 -45
- package/dist/kits/auth-core/lib/validation/forms.ts +1 -2
- package/dist/kits/auth-core/package-deps.json +1 -1
- package/dist/kits/auth-core/types/next-auth.d.ts +1 -1
- package/dist/kits/blocks/.nextworks/docs/BLOCKS_QUICKSTART.md +2 -8
- package/dist/kits/blocks/.nextworks/docs/THEME_GUIDE.md +18 -1
- package/dist/kits/blocks/app/templates/productlaunch/page.tsx +0 -2
- package/dist/kits/blocks/components/sections/FAQ.tsx +0 -1
- package/dist/kits/blocks/components/sections/Newsletter.tsx +2 -2
- package/dist/kits/blocks/components/ui/switch.tsx +78 -78
- package/dist/kits/blocks/package-deps.json +3 -3
- package/dist/kits/data/.nextworks/docs/DATA_QUICKSTART.md +128 -112
- package/dist/kits/data/.nextworks/docs/DATA_README.md +2 -1
- package/dist/kits/data/app/api/posts/[id]/route.ts +83 -83
- package/dist/kits/data/app/api/posts/route.ts +136 -138
- package/dist/kits/data/app/api/seed-demo/route.ts +1 -2
- package/dist/kits/data/app/api/users/[id]/route.ts +29 -17
- package/dist/kits/data/app/api/users/check-email/route.ts +1 -1
- package/dist/kits/data/app/api/users/check-unique/route.ts +30 -27
- package/dist/kits/data/app/api/users/route.ts +0 -2
- package/dist/kits/data/app/examples/demo/create-post-form.tsx +108 -106
- package/dist/kits/data/app/examples/demo/page.tsx +2 -1
- package/dist/kits/data/app/examples/demo/seed-demo-button.tsx +1 -1
- package/dist/kits/data/components/admin/posts-manager.tsx +727 -719
- package/dist/kits/data/components/admin/users-manager.tsx +435 -432
- package/dist/kits/data/lib/server/result.ts +5 -2
- package/dist/kits/data/package-deps.json +1 -1
- package/dist/kits/data/scripts/seed-demo.mjs +1 -2
- package/dist/kits/forms/app/api/wizard/route.ts +76 -71
- package/dist/kits/forms/app/examples/forms/server-action/page.tsx +78 -71
- package/dist/kits/forms/components/hooks/useCheckUnique.ts +85 -79
- package/dist/kits/forms/components/ui/form/form-control.tsx +28 -28
- package/dist/kits/forms/components/ui/form/form-description.tsx +23 -22
- package/dist/kits/forms/components/ui/form/form-item.tsx +21 -21
- package/dist/kits/forms/components/ui/form/form-label.tsx +24 -24
- package/dist/kits/forms/components/ui/form/form-message.tsx +28 -29
- package/dist/kits/forms/components/ui/switch.tsx +78 -78
- package/dist/kits/forms/lib/forms/map-errors.ts +1 -1
- package/dist/kits/forms/lib/validation/forms.ts +1 -2
- package/package.json +1 -1
|
@@ -1,106 +1,108 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import React from "react";
|
|
4
|
-
import { useForm } from "react-hook-form";
|
|
5
|
-
import { zodResolver } from "@hookform/resolvers/zod";
|
|
6
|
-
import { postSchema } from "@/lib/validation/forms";
|
|
7
|
-
import { z } from "zod";
|
|
8
|
-
import { useRouter } from "next/navigation";
|
|
9
|
-
import { Form } from "@/components/ui/form/form";
|
|
10
|
-
import { FormField } from "@/components/ui/form/form-field";
|
|
11
|
-
import { FormItem } from "@/components/ui/form/form-item";
|
|
12
|
-
import { FormLabel } from "@/components/ui/form/form-label";
|
|
13
|
-
import { FormControl } from "@/components/ui/form/form-control";
|
|
14
|
-
import { FormMessage } from "@/components/ui/form/form-message";
|
|
15
|
-
import { Input } from "@/components/ui/input";
|
|
16
|
-
import { Textarea } from "@/components/ui/textarea";
|
|
17
|
-
import { Button } from "@/components/ui/button";
|
|
18
|
-
import { mapApiErrorsToForm } from "@/lib/forms/map-errors";
|
|
19
|
-
import { toast } from "sonner";
|
|
20
|
-
|
|
21
|
-
import { useSession } from "next-auth/react";
|
|
22
|
-
|
|
23
|
-
export default function CreatePostForm() {
|
|
24
|
-
// Relax the schema for this demo form: authorId is optional here
|
|
25
|
-
const postFormSchema = postSchema.extend({
|
|
26
|
-
authorId: postSchema.shape.authorId.optional().or(z.literal("")),
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const methods = useForm({
|
|
30
|
-
resolver: zodResolver(postFormSchema),
|
|
31
|
-
defaultValues: { title: "", content: "" },
|
|
32
|
-
});
|
|
33
|
-
const { control, handleSubmit, reset } = methods;
|
|
34
|
-
|
|
35
|
-
const session = useSession();
|
|
36
|
-
const router = useRouter();
|
|
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
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { useForm } from "react-hook-form";
|
|
5
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
6
|
+
import { postSchema } from "@/lib/validation/forms";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { useRouter } from "next/navigation";
|
|
9
|
+
import { Form } from "@/components/ui/form/form";
|
|
10
|
+
import { FormField } from "@/components/ui/form/form-field";
|
|
11
|
+
import { FormItem } from "@/components/ui/form/form-item";
|
|
12
|
+
import { FormLabel } from "@/components/ui/form/form-label";
|
|
13
|
+
import { FormControl } from "@/components/ui/form/form-control";
|
|
14
|
+
import { FormMessage } from "@/components/ui/form/form-message";
|
|
15
|
+
import { Input } from "@/components/ui/input";
|
|
16
|
+
import { Textarea } from "@/components/ui/textarea";
|
|
17
|
+
import { Button } from "@/components/ui/button";
|
|
18
|
+
import { mapApiErrorsToForm } from "@/lib/forms/map-errors";
|
|
19
|
+
import { toast } from "sonner";
|
|
20
|
+
|
|
21
|
+
import { useSession } from "next-auth/react";
|
|
22
|
+
|
|
23
|
+
export default function CreatePostForm() {
|
|
24
|
+
// Relax the schema for this demo form: authorId is optional here
|
|
25
|
+
const postFormSchema = postSchema.extend({
|
|
26
|
+
authorId: postSchema.shape.authorId.optional().or(z.literal("")),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const methods = useForm({
|
|
30
|
+
resolver: zodResolver(postFormSchema),
|
|
31
|
+
defaultValues: { title: "", content: "" },
|
|
32
|
+
});
|
|
33
|
+
const { control, handleSubmit, reset } = methods;
|
|
34
|
+
|
|
35
|
+
const session = useSession();
|
|
36
|
+
const router = useRouter();
|
|
37
|
+
|
|
38
|
+
type CreatePostFormValues = z.infer<typeof postFormSchema>;
|
|
39
|
+
|
|
40
|
+
const onSubmit = async (values: CreatePostFormValues) => {
|
|
41
|
+
if (session.status !== "authenticated") {
|
|
42
|
+
toast.error(
|
|
43
|
+
"You must be signed in to create a post. Use the Sign up / Log in links above.",
|
|
44
|
+
);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const res = await fetch("/api/posts", {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: { "Content-Type": "application/json" },
|
|
51
|
+
body: JSON.stringify(values),
|
|
52
|
+
});
|
|
53
|
+
const payload = await res.json().catch(() => null);
|
|
54
|
+
if (!res.ok || !payload?.success) {
|
|
55
|
+
const msg = payload ? mapApiErrorsToForm(methods, payload) : undefined;
|
|
56
|
+
toast.error(msg || payload?.message || "Create failed");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
reset();
|
|
60
|
+
toast.success("Post created");
|
|
61
|
+
// Refresh the server-rendered list below
|
|
62
|
+
router.refresh();
|
|
63
|
+
} catch {
|
|
64
|
+
toast.error("Create failed");
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div className="bg-card rounded-md p-6">
|
|
70
|
+
<h3 className="mb-3 text-lg font-semibold">
|
|
71
|
+
Create a post (requires sign in)
|
|
72
|
+
</h3>
|
|
73
|
+
<Form methods={methods}>
|
|
74
|
+
<form onSubmit={handleSubmit(onSubmit)} className="space-y-3">
|
|
75
|
+
<FormField
|
|
76
|
+
control={control}
|
|
77
|
+
name="title"
|
|
78
|
+
render={({ field }) => (
|
|
79
|
+
<FormItem>
|
|
80
|
+
<FormLabel>Title</FormLabel>
|
|
81
|
+
<FormControl>
|
|
82
|
+
<Input {...field} />
|
|
83
|
+
</FormControl>
|
|
84
|
+
<FormMessage />
|
|
85
|
+
</FormItem>
|
|
86
|
+
)}
|
|
87
|
+
/>
|
|
88
|
+
|
|
89
|
+
<FormField
|
|
90
|
+
control={control}
|
|
91
|
+
name="content"
|
|
92
|
+
render={({ field }) => (
|
|
93
|
+
<FormItem>
|
|
94
|
+
<FormLabel>Content</FormLabel>
|
|
95
|
+
<FormControl>
|
|
96
|
+
<Textarea {...field} rows={4} />
|
|
97
|
+
</FormControl>
|
|
98
|
+
<FormMessage />
|
|
99
|
+
</FormItem>
|
|
100
|
+
)}
|
|
101
|
+
/>
|
|
102
|
+
|
|
103
|
+
<Button type="submit">Create Post</Button>
|
|
104
|
+
</form>
|
|
105
|
+
</Form>
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
@@ -79,7 +79,8 @@ export default async function DemoPage() {
|
|
|
79
79
|
<h2 className="mb-3 text-lg font-semibold">Your posts</h2>
|
|
80
80
|
{posts.length === 0 ? (
|
|
81
81
|
<p className="text-muted-foreground text-sm">
|
|
82
|
-
|
|
82
|
+
No posts yet. Use the form above or click "Seed demo data" to create
|
|
83
|
+
|
|
83
84
|
sample posts.
|
|
84
85
|
</p>
|
|
85
86
|
) : (
|
|
@@ -22,7 +22,7 @@ export default function SeedDemoButton() {
|
|
|
22
22
|
toast.success("Demo data seeded");
|
|
23
23
|
// Refresh to show new posts if the page lists them
|
|
24
24
|
router.refresh();
|
|
25
|
-
} catch
|
|
25
|
+
} catch {
|
|
26
26
|
toast.error("Failed to seed demo data");
|
|
27
27
|
} finally {
|
|
28
28
|
setLoading(false);
|