remix-validated-form 0.0.4 → 1.1.1-beta.1

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.
Files changed (72) hide show
  1. package/.eslintcache +1 -1
  2. package/.prettierignore +2 -0
  3. package/README.md +76 -19
  4. package/browser/ValidatedForm.d.ts +22 -0
  5. package/browser/ValidatedForm.js +5 -2
  6. package/browser/flatten.d.ts +4 -0
  7. package/browser/flatten.js +35 -0
  8. package/browser/hooks.d.ts +28 -3
  9. package/browser/hooks.js +17 -2
  10. package/browser/index.d.ts +2 -0
  11. package/browser/index.js +2 -0
  12. package/browser/internal/flatten.d.ts +4 -0
  13. package/browser/internal/flatten.js +35 -0
  14. package/browser/internal/formContext.d.ts +18 -0
  15. package/browser/server.d.ts +5 -0
  16. package/browser/server.js +5 -0
  17. package/browser/test-data/testFormData.d.ts +15 -0
  18. package/browser/test-data/testFormData.js +46 -0
  19. package/browser/validation/createValidator.d.ts +7 -0
  20. package/browser/validation/createValidator.js +19 -0
  21. package/browser/validation/types.d.ts +14 -2
  22. package/browser/validation/validation.test.js +221 -8
  23. package/browser/validation/withYup.d.ts +3 -0
  24. package/browser/validation/withYup.js +31 -25
  25. package/browser/validation/withZod.d.ts +6 -0
  26. package/browser/validation/withZod.js +50 -0
  27. package/build/ValidatedForm.d.ts +22 -0
  28. package/build/ValidatedForm.js +5 -2
  29. package/build/flatten.d.ts +4 -0
  30. package/build/flatten.js +43 -0
  31. package/build/hooks.d.ts +28 -3
  32. package/build/hooks.js +20 -2
  33. package/build/index.d.ts +2 -0
  34. package/build/index.js +2 -0
  35. package/build/internal/flatten.d.ts +4 -0
  36. package/build/internal/flatten.js +43 -0
  37. package/build/internal/formContext.d.ts +18 -0
  38. package/build/server.d.ts +5 -0
  39. package/build/server.js +5 -0
  40. package/build/test-data/testFormData.d.ts +15 -0
  41. package/build/test-data/testFormData.js +50 -0
  42. package/build/validation/createValidator.d.ts +7 -0
  43. package/build/validation/createValidator.js +23 -0
  44. package/build/validation/types.d.ts +14 -2
  45. package/build/validation/validation.test.js +221 -8
  46. package/build/validation/withYup.d.ts +3 -0
  47. package/build/validation/withYup.js +31 -25
  48. package/build/validation/withZod.d.ts +6 -0
  49. package/build/validation/withZod.js +57 -0
  50. package/package.json +20 -14
  51. package/sample-app/.env +7 -0
  52. package/sample-app/README.md +53 -0
  53. package/sample-app/app/components/ErrorBox.tsx +34 -0
  54. package/sample-app/app/components/FormInput.tsx +40 -0
  55. package/sample-app/app/components/FormSelect.tsx +37 -0
  56. package/sample-app/app/components/SubjectForm.tsx +150 -0
  57. package/sample-app/app/entry.client.tsx +4 -0
  58. package/sample-app/app/entry.server.tsx +21 -0
  59. package/sample-app/app/root.tsx +92 -0
  60. package/sample-app/app/routes/index.tsx +5 -0
  61. package/sample-app/app/routes/subjects/$id.edit.tsx +98 -0
  62. package/sample-app/app/routes/subjects/index.tsx +112 -0
  63. package/sample-app/app/routes/subjects/new.tsx +46 -0
  64. package/sample-app/app/services/db.server.ts +23 -0
  65. package/sample-app/app/types.ts +6 -0
  66. package/sample-app/package-lock.json +10890 -0
  67. package/sample-app/package.json +36 -0
  68. package/sample-app/prisma/dev.db +0 -0
  69. package/sample-app/prisma/schema.prisma +34 -0
  70. package/sample-app/public/favicon.ico +0 -0
  71. package/sample-app/remix.config.js +10 -0
  72. package/sample-app/remix.env.d.ts +2 -0
@@ -0,0 +1,46 @@
1
+ import { Box, Container, Heading } from "@chakra-ui/react";
2
+ import { ActionFunction, redirect } from "remix";
3
+ import { SubjectForm, subjectFormValidator } from "~/components/SubjectForm";
4
+ import { db } from "~/services/db.server";
5
+ import { validationError } from "../../../remix-validated-form";
6
+
7
+ export const action: ActionFunction = async ({ request }) => {
8
+ const fieldValues = subjectFormValidator.validate(await request.formData());
9
+ if (fieldValues.error) return validationError(fieldValues.error);
10
+
11
+ const { teacher, subjectDays, ...newSubject } = fieldValues.data;
12
+
13
+ await db.subject.create({
14
+ data: {
15
+ ...newSubject,
16
+ teacher: {
17
+ create: teacher,
18
+ },
19
+ subjectDays: {
20
+ create: subjectDays,
21
+ },
22
+ },
23
+ });
24
+
25
+ return redirect("/subjects");
26
+ };
27
+
28
+ export default function NewSubject() {
29
+ return (
30
+ <>
31
+ <Box bg="white" pt="4" pb="4" shadow="sm">
32
+ <Container maxW="7xl">
33
+ <Heading size="lg" mb="0">
34
+ Create Subject
35
+ </Heading>
36
+ </Container>
37
+ </Box>
38
+
39
+ <Box as="main" py="8" flex="1">
40
+ <Container maxW="7xl">
41
+ <SubjectForm />
42
+ </Container>
43
+ </Box>
44
+ </>
45
+ );
46
+ }
@@ -0,0 +1,23 @@
1
+ import { PrismaClient } from "@prisma/client";
2
+
3
+ let db: PrismaClient;
4
+
5
+ declare global {
6
+ var __db: PrismaClient | undefined;
7
+ }
8
+
9
+ // this is needed because in development we don't want to restart
10
+ // the server with every change, but we want to make sure we don't
11
+ // create a new connection to the DB with every change either.
12
+ if (process.env.NODE_ENV === "production") {
13
+ db = new PrismaClient();
14
+ db.$connect();
15
+ } else {
16
+ if (!global.__db) {
17
+ global.__db = new PrismaClient();
18
+ global.__db.$connect();
19
+ }
20
+ db = global.__db;
21
+ }
22
+
23
+ export { db };
@@ -0,0 +1,6 @@
1
+ import { Subject, SubjectDays, Teacher } from "@prisma/client";
2
+
3
+ export type SubjectComplete = Subject & {
4
+ teacher: Teacher;
5
+ subjectDays: SubjectDays[];
6
+ };