Merge remote-tracking branch 'origin/dev/guerby' into dev/cedric
This commit is contained in:
@@ -36,6 +36,7 @@ func HandleLogin(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(r.Body)
|
||||
fmt.Println(body)
|
||||
if err != nil {
|
||||
core.JSONError{
|
||||
Status: core.Error,
|
||||
|
||||
@@ -20,6 +20,7 @@ func HandleCreateUser(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("body : ", body )
|
||||
var user core.User
|
||||
err = json.Unmarshal(body, &user)
|
||||
if err != nil {
|
||||
@@ -30,7 +31,7 @@ func HandleCreateUser(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Println(user)
|
||||
log.Println("User : ", user)
|
||||
|
||||
res, err := user.Insert(context.Background())
|
||||
log.Println(res)
|
||||
|
||||
@@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
||||
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/csrf v1.7.2 h1:oTUjx0vyf2T+wkrx09Trsev1TE+/EbDAeHtSTbtC2eI=
|
||||
|
||||
@@ -21,25 +21,45 @@ import {
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import useApiMutation from "@/hooks/use-api";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectLabel,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select"
|
||||
|
||||
const formSchema = z.object({
|
||||
firstname: z.string().min(2, { message: "Prénom trop court" }),
|
||||
lastname: z.string().min(2, { message: "Nom trop court" }),
|
||||
firstname: z.string().min(2, { message: "Prénom trop court." }),
|
||||
lastname: z.string().min(2, { message: "Nom trop court." }),
|
||||
role: z.enum(["admin", "user"], { message: "Rôle invalide." }),
|
||||
phone: z
|
||||
.string()
|
||||
.min(10, { message: "Un numéro de téléphone à 10 chiffres" }),
|
||||
email: z.string().email({ message: "Invalid email address" }),
|
||||
message: z
|
||||
.string()
|
||||
.min(10, { message: "Message must be at least 10 characters long" }),
|
||||
.max(10, { message: "Un numéro de téléphone à 10 chiffres." })
|
||||
.optional(),
|
||||
email: z.string().email({ message: "Email invalide." })
|
||||
});
|
||||
|
||||
export default function ContactFormPreview() {
|
||||
export default function CreateMemberForm() {
|
||||
const {
|
||||
trigger
|
||||
} = useApiMutation(
|
||||
"/users/new",
|
||||
{ onSuccess: () => console.log("Member created") },
|
||||
"POST",
|
||||
true,
|
||||
false
|
||||
)
|
||||
|
||||
const form = useForm<z.infer<typeof formSchema>>({
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues: {
|
||||
firstname: "",
|
||||
lastname: "",
|
||||
role: "user",
|
||||
phone: "",
|
||||
email: "",
|
||||
},
|
||||
@@ -47,25 +67,24 @@ export default function ContactFormPreview() {
|
||||
|
||||
async function onSubmit(values: z.infer<typeof formSchema>) {
|
||||
try {
|
||||
console.log(values);
|
||||
await fetch("/api/users/new", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(values),
|
||||
});
|
||||
const res = await trigger(values)
|
||||
if (!res) throw new Error("The server hasn't responded.");
|
||||
if (res.status === "Error") throw new Error(res.message);
|
||||
} catch (error) {
|
||||
console.error("Form submission error", error);
|
||||
}
|
||||
console.log("subimted");
|
||||
console.log("submited");
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex min-h-[60vh] h-full w-full items-center justify-center px-4">
|
||||
<Card className="mx-auto max-w-md">
|
||||
<CardHeader>
|
||||
<CardTitle className="text-2xl">Contact Us</CardTitle>
|
||||
<CardTitle className="text-2xl">Création de membre</CardTitle>
|
||||
<CardDescription>
|
||||
Please fill out the form below and we will get back to
|
||||
you shortly.
|
||||
Remplissez les différents champs pour créer un membre.
|
||||
Un code sera envoyé par mail à l'utilisateur.
|
||||
Il pourra ensuite modifier le mot de passe de son compte avec ce code.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
@@ -90,6 +109,7 @@ export default function ContactFormPreview() {
|
||||
placeholder="John Doe"
|
||||
type="text"
|
||||
autoComplete="firstname"
|
||||
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
@@ -113,6 +133,7 @@ export default function ContactFormPreview() {
|
||||
placeholder="John Doe"
|
||||
type="text"
|
||||
autoComplete="lastname"
|
||||
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
@@ -136,6 +157,7 @@ export default function ContactFormPreview() {
|
||||
placeholder="johndoe@mail.com"
|
||||
type="email"
|
||||
autoComplete="email"
|
||||
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
@@ -144,7 +166,36 @@ export default function ContactFormPreview() {
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Message Field */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="role"
|
||||
render={({ field }) => (
|
||||
<FormItem className="grid gap-2">
|
||||
<FormLabel htmlFor="role">
|
||||
Role
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Select
|
||||
value={field.value}
|
||||
onValueChange={(value: string) => field.onChange(value)}>
|
||||
<SelectTrigger className="w-[180px]">
|
||||
<SelectValue placeholder="Select a role" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectLabel>Role</SelectLabel>
|
||||
<SelectItem value="admin">Administrateur</SelectItem>
|
||||
<SelectItem value="user">Utilisateur</SelectItem>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Phone Field */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="phone"
|
||||
@@ -157,8 +208,9 @@ export default function ContactFormPreview() {
|
||||
<Input
|
||||
id="phone"
|
||||
placeholder="0648265441"
|
||||
type="number"
|
||||
type="tel"
|
||||
autoComplete="phone"
|
||||
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
|
||||
Reference in New Issue
Block a user