-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Andrej Arbanas <[email protected]>
- Loading branch information
Showing
8 changed files
with
161 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
"use client"; | ||
import MainLayout from "~/components/layout/mainLayout"; | ||
import { useParams } from "next/navigation"; | ||
import { api } from "~/trpc/react"; | ||
import FormComponent from "~/components/organisms/form/formComponent/FormComponent"; | ||
import { useForm } from "react-hook-form"; | ||
import LoadingSpinner from "~/components/organisms/loadingSpinner/LoadingSpinner"; | ||
import FormInput from "~/components/organisms/form/formInput/FormInput"; | ||
import FormSwitch from "~/components/organisms/form/formSwitch/FormSwitch"; | ||
import { Button } from "~/components/atoms/Button"; | ||
|
||
type FindUserReturnDTO = { | ||
id: string; | ||
email: string; | ||
active: boolean; | ||
firstname: string; | ||
lastname: string; | ||
}; | ||
|
||
export default function UserDetailPage() { | ||
const { id } = useParams(); // Get the user ID from the URL | ||
|
||
// Fetch user data by ID | ||
const { data, isLoading, error } = api.user.findById.useQuery({ | ||
id: id as string, | ||
}); | ||
|
||
const form = useForm<FindUserReturnDTO>({ | ||
defaultValues: { | ||
email: data?.email ?? "", | ||
active: data?.active ?? false, | ||
firstname: data?.profile?.firstName ?? "", | ||
lastname: data?.profile?.lastName ?? "", | ||
}, | ||
}); | ||
// Handle form submission | ||
const handleSubmit = async (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
// Implementation for form submission goes here | ||
}; | ||
|
||
return ( | ||
<MainLayout | ||
headerChildren={ | ||
<h1 className="text-xl font-bold"> | ||
Uređivanje volontera {data?.profile?.firstName}{" "} | ||
{data?.profile?.lastName} | ||
</h1> | ||
} | ||
> | ||
<div> | ||
{isLoading && <LoadingSpinner />} | ||
{error && <div>Greška</div>} | ||
|
||
<FormComponent form={form} onSubmit={handleSubmit}> | ||
<FormInput | ||
id="firstname" | ||
label="Ime*" | ||
{...form.register("firstname", { | ||
required: "Ime je obavezno polje", | ||
})} | ||
/> | ||
|
||
<FormInput | ||
id="lastname" | ||
label="Prezime*" | ||
{...form.register("lastname", { | ||
required: "Prezime je obavezno polje", | ||
})} | ||
/> | ||
|
||
<FormInput | ||
id="email" | ||
label="Email*" | ||
{...form.register("email", { | ||
required: "Email je obavezno polje", | ||
})} | ||
/> | ||
|
||
<FormSwitch | ||
id="active" | ||
label="Aktivan" | ||
active={data?.active ?? false} | ||
setActive={() => { | ||
console.log("Switched"); | ||
}} | ||
/> | ||
|
||
<Button className="bg-black !text-base text-white" type="submit"> | ||
<span>Spremi promjene</span> | ||
</Button> | ||
</FormComponent> | ||
</div> | ||
</MainLayout> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from "react"; | ||
import * as Switch from "@radix-ui/react-switch"; | ||
|
||
type FormSwitchProps = { | ||
id: string; | ||
label: string; | ||
active: boolean; | ||
setActive: () => void; | ||
}; | ||
|
||
// eslint-disable-next-line react/display-name | ||
const FormSwitch: React.FC<FormSwitchProps> = ({ | ||
id, | ||
label, | ||
setActive, | ||
active, | ||
}) => { | ||
return ( | ||
<div> | ||
<label htmlFor={id}>{label}</label> | ||
<Switch.Root | ||
className="bg-blackA6 shadow-blackA4 relative h-[25px] w-[42px] cursor-pointer rounded-full shadow-[0_2px_10px] outline-none focus:shadow-[0_0_0_2px] focus:shadow-black data-[state=checked]:bg-black" | ||
id="active" | ||
checked={active} | ||
onCheckedChange={setActive} | ||
> | ||
<Switch.Thumb className="shadow-blackA4 block h-[21px] w-[21px] translate-x-0.5 rounded-full bg-white shadow-[0_2px_2px] transition-transform duration-100 will-change-transform data-[state=checked]:translate-x-[19px]" /> | ||
</Switch.Root> | ||
</div> | ||
); | ||
}; | ||
|
||
export default FormSwitch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1426,6 +1426,19 @@ | |
dependencies: | ||
"@radix-ui/react-compose-refs" "1.1.0" | ||
|
||
"@radix-ui/react-switch@^1.1.0": | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/@radix-ui/react-switch/-/react-switch-1.1.0.tgz#fcf8e778500f1d60d4b2bec2fc3fad77a7c118e3" | ||
integrity sha512-OBzy5WAj641k0AOSpKQtreDMe+isX0MQJ1IVyF03ucdF3DunOnROVrjWs8zsXUxC3zfZ6JL9HFVCUlMghz9dJw== | ||
dependencies: | ||
"@radix-ui/primitive" "1.1.0" | ||
"@radix-ui/react-compose-refs" "1.1.0" | ||
"@radix-ui/react-context" "1.1.0" | ||
"@radix-ui/react-primitive" "2.0.0" | ||
"@radix-ui/react-use-controllable-state" "1.1.0" | ||
"@radix-ui/react-use-previous" "1.1.0" | ||
"@radix-ui/react-use-size" "1.1.0" | ||
|
||
"@radix-ui/[email protected]": | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/@radix-ui/react-use-callback-ref/-/react-use-callback-ref-1.1.0.tgz#bce938ca413675bc937944b0d01ef6f4a6dc5bf1" | ||
|
@@ -1450,6 +1463,11 @@ | |
resolved "https://registry.yarnpkg.com/@radix-ui/react-use-layout-effect/-/react-use-layout-effect-1.1.0.tgz#3c2c8ce04827b26a39e442ff4888d9212268bd27" | ||
integrity sha512-+FPE0rOdziWSrH9athwI1R0HDVbWlEhd+FR+aSDk4uWGmSJ9Z54sdZVDQPZAinJhJXwfT+qnj969mCsT2gfm5w== | ||
|
||
"@radix-ui/[email protected]": | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/@radix-ui/react-use-previous/-/react-use-previous-1.1.0.tgz#d4dd37b05520f1d996a384eb469320c2ada8377c" | ||
integrity sha512-Z/e78qg2YFnnXcW88A4JmTtm4ADckLno6F7OXotmkQfeuCVaKuYzqAATPhVzl3delXE7CxIV8shofPn3jPc5Og== | ||
|
||
"@radix-ui/[email protected]": | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/@radix-ui/react-use-rect/-/react-use-rect-1.1.0.tgz#13b25b913bd3e3987cc9b073a1a164bb1cf47b88" | ||
|