Fixed gradient not saving correctly
This commit is contained in:
parent
ea11b16f58
commit
705dd6acea
3 changed files with 31 additions and 14 deletions
|
|
@ -6,7 +6,7 @@ export default function GradientChooserComponent({value, onChange}){
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-wrap gap-4 justify-center items-center">
|
<div className="flex flex-wrap gap-4 justify-center items-center">
|
||||||
{gradients.map((gradient, idx) =>
|
{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 onClick={() => {onChange(gradient)}} className={"cursor-pointer w-12 h-12 rounded-full transition-all duration-400 " + gradient + (value === gradient ? " shadow-lg ring-2 ring-primary" : "")} key={idx}></div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -139,7 +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 " +
|
||||||
(userData!.profile_image ?? gradients[parseInt(userData!.id ?? "", 30) % gradients.length])
|
(userData?.profile_image ?? gradients[parseInt(userData?.id ?? "", 30) % gradients.length])
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import * as Form from "@radix-ui/react-form";
|
import * as Form from "@radix-ui/react-form";
|
||||||
|
import { cloneDeep } from "lodash";
|
||||||
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 GradientChooserComponent from "../../components/gradientChooserComponent";
|
||||||
|
|
@ -27,7 +28,7 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
setTabId("");
|
setTabId("");
|
||||||
}, []);
|
}, []);
|
||||||
const { setErrorData, setSuccessData } = useContext(alertContext);
|
const { setErrorData, setSuccessData } = useContext(alertContext);
|
||||||
const { userData } = useContext(AuthContext);
|
const { userData, setUserData } = useContext(AuthContext);
|
||||||
const { password, cnfPassword, gradient } = inputState;
|
const { password, cnfPassword, gradient } = inputState;
|
||||||
|
|
||||||
function handlePatchUser() {
|
function handlePatchUser() {
|
||||||
|
|
@ -38,12 +39,21 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try{
|
try {
|
||||||
updateUser(userData!.id, { password, profile_image: gradient }).then(() => {setSuccessData({title: "Changes saved successfully!"})});
|
updateUser(userData!.id, { password, profile_image: gradient }).then(
|
||||||
} catch (error) {
|
() => {
|
||||||
setErrorData({title: "Error saving changes", list: [error as string]});
|
setSuccessData({ title: "Changes saved successfully!" });
|
||||||
}
|
if (gradient !== "") {
|
||||||
|
let newUserData = cloneDeep(userData);
|
||||||
|
newUserData!.profile_image = gradient;
|
||||||
|
|
||||||
|
setUserData(newUserData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
setErrorData({ title: "Error saving changes", list: [error as string] });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleInput({
|
function handleInput({
|
||||||
|
|
@ -131,7 +141,14 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
|
|
||||||
<div className="mt-4 w-[1010px]">
|
<div className="mt-4 w-[1010px]">
|
||||||
<GradientChooserComponent
|
<GradientChooserComponent
|
||||||
value={gradient == "" ? (userData!.profile_image ?? gradients[parseInt(userData!.id ?? "", 30) % gradients.length]) : gradient}
|
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 } });
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue