summaryrefslogtreecommitdiff
path: root/src/pages/logintest/Form.tsx
blob: a593acb68ffc103e646aec2fa1e0289b864bbafe (plain)
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
"use client";

import { useFormStatus } from "react-dom";

const SubmitButton = () => {
  const { pending } = useFormStatus();
  return (
    <>
      <button
        disabled={pending}
        type="submit"
        className="hover:bg-slate-50 w-fit rounded-lg bg-white p-2"
      >
        {pending ? "Pending..." : "Submit"}
      </button>
    </>
  );
};

export const Form = ({
  message,
  greet,
}: {
  message: Promise<string>;
  greet: (formData: FormData) => Promise<void>;
}) => (
  <div style={{ border: "3px blue dashed", margin: "1em", padding: "1em" }}>
    <p>{message}</p>
    <form action={greet}>
      <div className="flex flex-col gap-1 text-left">
        <div>
          Name:{" "}
          <input
            name="name"
            required
            className="invalid:border-red-500 rounded-sm border px-2 py-1"
          />
        </div>
        <div>
          Email:{" "}
          <input
            type="email"
            name="email"
            required
            className="invalid:border-red-500 rounded-sm border px-2 py-1"
          />
        </div>
        <SubmitButton />
      </div>
    </form>
    <h3>This is a client component.</h3>
  </div>
);