Added gradient chooser and success messages
This commit is contained in:
parent
b770622603
commit
bd44500508
6 changed files with 86 additions and 72 deletions
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { useState } from "react";
|
||||||
|
import { gradients } from "../../utils/styleUtils";
|
||||||
|
|
||||||
|
|
||||||
|
export default function GradientChooserComponent({value, onChange}){
|
||||||
|
return (
|
||||||
|
<div className="flex flex-wrap gap-4 justify-center items-center">
|
||||||
|
{gradients.map((gradient, idx) =>
|
||||||
|
<div onClick={() => {onChange(gradient)}} className={"w-12 h-12 rounded-full transition-all duration-400 " + gradient + (value === gradient ? " shadow-lg ring-2 ring-primary" : "")} key={idx}></div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -139,9 +139,7 @@ export default function Header(): JSX.Element {
|
||||||
<button
|
<button
|
||||||
className={
|
className={
|
||||||
"h-7 w-7 rounded-full focus-visible:outline-0 " +
|
"h-7 w-7 rounded-full focus-visible:outline-0 " +
|
||||||
gradients[
|
(userData!.profile_image ?? gradients[parseInt(userData!.id ?? "", 30) % gradients.length])
|
||||||
parseInt(userData?.id ?? "", 30) % gradients.length
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ export function AuthProvider({ children }): React.ReactElement {
|
||||||
.then((user) => {
|
.then((user) => {
|
||||||
setUserData(user);
|
setUserData(user);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
const isSuperUser = user.is_superuser;
|
const isSuperUser = user!.is_superuser;
|
||||||
setIsAdmin(isSuperUser);
|
setIsAdmin(isSuperUser);
|
||||||
})
|
})
|
||||||
.catch((error) => {});
|
.catch((error) => {});
|
||||||
|
|
|
||||||
|
|
@ -463,6 +463,8 @@ export async function updateUser(user_id: string, user: changeUser) {
|
||||||
const res = await api.patch(`${BASE_URL_API}users/${user_id}`, user);
|
const res = await api.patch(`${BASE_URL_API}users/${user_id}`, user);
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
return res.data;
|
return res.data;
|
||||||
|
} else {
|
||||||
|
throw new Error(res.data.toString());
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Error:", error);
|
console.log("Error:", error);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import * as Form from "@radix-ui/react-form";
|
import * as Form from "@radix-ui/react-form";
|
||||||
import { useContext, useEffect, useState } from "react";
|
import { useContext, useEffect, useState } from "react";
|
||||||
import IconComponent from "../../components/genericIconComponent";
|
import IconComponent from "../../components/genericIconComponent";
|
||||||
|
import GradientChooserComponent from "../../components/gradientChooserComponent";
|
||||||
import Header from "../../components/headerComponent";
|
import Header from "../../components/headerComponent";
|
||||||
import InputComponent from "../../components/inputComponent";
|
import InputComponent from "../../components/inputComponent";
|
||||||
import { Button } from "../../components/ui/button";
|
import { Button } from "../../components/ui/button";
|
||||||
|
|
@ -13,6 +14,7 @@ import {
|
||||||
inputHandlerEventType,
|
inputHandlerEventType,
|
||||||
patchUserInputStateType,
|
patchUserInputStateType,
|
||||||
} from "../../types/components";
|
} from "../../types/components";
|
||||||
|
import { gradients } from "../../utils/styleUtils";
|
||||||
export default function ProfileSettingsPage(): JSX.Element {
|
export default function ProfileSettingsPage(): JSX.Element {
|
||||||
const { setTabId } = useContext(TabsContext);
|
const { setTabId } = useContext(TabsContext);
|
||||||
|
|
||||||
|
|
@ -24,7 +26,7 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTabId("");
|
setTabId("");
|
||||||
}, []);
|
}, []);
|
||||||
const { setErrorData } = useContext(alertContext);
|
const { setErrorData, setSuccessData } = useContext(alertContext);
|
||||||
const { userData } = useContext(AuthContext);
|
const { userData } = useContext(AuthContext);
|
||||||
const { password, cnfPassword, gradient } = inputState;
|
const { password, cnfPassword, gradient } = inputState;
|
||||||
|
|
||||||
|
|
@ -36,8 +38,12 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
try{
|
||||||
|
updateUser(userData!.id, { password, profile_image: gradient }).then(() => {setSuccessData({title: "Changes saved successfully!"})});
|
||||||
|
} catch (error) {
|
||||||
|
setErrorData({title: "Error saving changes", list: [error as string]});
|
||||||
|
}
|
||||||
|
|
||||||
updateUser(userData!.id, {password, profile_image: gradient});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleInput({
|
function handleInput({
|
||||||
|
|
@ -67,13 +73,14 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
const data = Object.fromEntries(new FormData(event.currentTarget));
|
const data = Object.fromEntries(new FormData(event.currentTarget));
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
className="flex justify-between px-6"
|
className="flex h-full flex-col px-6 pb-16"
|
||||||
>
|
>
|
||||||
|
<div className="flex h-full flex-col gap-4">
|
||||||
<div className="flex gap-4">
|
<div className="flex gap-4">
|
||||||
<div className="mb-3 w-96">
|
<div className="mb-3 w-96">
|
||||||
<Form.Field name="password">
|
<Form.Field name="password">
|
||||||
<Form.Label className="data-[invalid]:label-invalid">
|
<Form.Label className="data-[invalid]:label-invalid">
|
||||||
Password <span className="font-medium text-destructive">*</span>
|
Password{" "}
|
||||||
</Form.Label>
|
</Form.Label>
|
||||||
|
|
||||||
<Form.Control asChild>
|
<Form.Control asChild>
|
||||||
|
|
@ -84,7 +91,6 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
value={password}
|
value={password}
|
||||||
isForm
|
isForm
|
||||||
password={true}
|
password={true}
|
||||||
required
|
|
||||||
placeholder="Password"
|
placeholder="Password"
|
||||||
className="w-full"
|
className="w-full"
|
||||||
/>
|
/>
|
||||||
|
|
@ -99,7 +105,6 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
<Form.Field name="cnfPassword">
|
<Form.Field name="cnfPassword">
|
||||||
<Form.Label className="data-[invalid]:label-invalid">
|
<Form.Label className="data-[invalid]:label-invalid">
|
||||||
Confirm Password{" "}
|
Confirm Password{" "}
|
||||||
<span className="font-medium text-destructive">*</span>
|
|
||||||
</Form.Label>
|
</Form.Label>
|
||||||
|
|
||||||
<InputComponent
|
<InputComponent
|
||||||
|
|
@ -109,7 +114,6 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
value={cnfPassword}
|
value={cnfPassword}
|
||||||
isForm
|
isForm
|
||||||
password={true}
|
password={true}
|
||||||
required
|
|
||||||
placeholder="Confirm Password"
|
placeholder="Confirm Password"
|
||||||
className="w-full"
|
className="w-full"
|
||||||
/>
|
/>
|
||||||
|
|
@ -118,37 +122,33 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
Please confirm your password
|
Please confirm your password
|
||||||
</Form.Message>
|
</Form.Message>
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<Form.Field name="gradient">
|
<Form.Field name="gradient">
|
||||||
<Form.Label className="data-[invalid]:label-invalid">
|
<Form.Label className="data-[invalid]:label-invalid">
|
||||||
Insert Gradient{" "}
|
Profile Gradient{" "}
|
||||||
<span className="font-medium text-destructive">*</span>
|
|
||||||
</Form.Label>
|
</Form.Label>
|
||||||
|
|
||||||
<InputComponent
|
<div className="mt-4 w-[1010px]">
|
||||||
|
<GradientChooserComponent
|
||||||
|
value={gradient == "" ? (userData!.profile_image ?? gradients[parseInt(userData!.id ?? "", 30) % gradients.length]) : gradient}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
handleInput({ target: { name: "gradient", value } });
|
handleInput({ target: { name: "gradient", value } });
|
||||||
}}
|
}}
|
||||||
value={gradient}
|
|
||||||
isForm
|
|
||||||
password={true}
|
|
||||||
required
|
|
||||||
placeholder="Insert Gradient"
|
|
||||||
className="w-full"
|
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
<Form.Message className="field-invalid" match="valueMissing">
|
|
||||||
Please insert gradient
|
|
||||||
</Form.Message>
|
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div className="w-40">
|
<div className="flex w-full justify-end">
|
||||||
|
<div className="w-32">
|
||||||
<Form.Submit asChild>
|
<Form.Submit asChild>
|
||||||
<Button className="mr-3 mt-6 w-full" type="submit">
|
<Button className="mr-3 mt-6 w-full" type="submit">
|
||||||
Save
|
Save
|
||||||
</Button>
|
</Button>
|
||||||
</Form.Submit>
|
</Form.Submit>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</Form.Root>
|
</Form.Root>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,7 @@ export type Users = {
|
||||||
username: string;
|
username: string;
|
||||||
is_active: boolean;
|
is_active: boolean;
|
||||||
is_superuser: boolean;
|
is_superuser: boolean;
|
||||||
|
profile_image: string;
|
||||||
create_at: Date;
|
create_at: Date;
|
||||||
updated_at: Date;
|
updated_at: Date;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue