Added gradient and changed types of patch user
This commit is contained in:
parent
04544b172f
commit
b770622603
6 changed files with 50 additions and 29 deletions
|
|
@ -140,7 +140,7 @@ export default function Header(): JSX.Element {
|
||||||
className={
|
className={
|
||||||
"h-7 w-7 rounded-full focus-visible:outline-0 " +
|
"h-7 w-7 rounded-full focus-visible:outline-0 " +
|
||||||
gradients[
|
gradients[
|
||||||
parseInt(userData?.id ?? "", 10) % gradients.length
|
parseInt(userData?.id ?? "", 30) % gradients.length
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -534,9 +534,10 @@ export const CONTROL_INPUT_STATE = {
|
||||||
username: "",
|
username: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CONTROL_RESET_PASSWORD_STATE = {
|
export const CONTROL_PATCH_USER_STATE = {
|
||||||
password: "",
|
password: "",
|
||||||
cnfPassword: "",
|
cnfPassword: "",
|
||||||
|
gradient: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CONTROL_LOGIN_STATE = {
|
export const CONTROL_LOGIN_STATE = {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import {
|
||||||
APIObjectType,
|
APIObjectType,
|
||||||
LoginType,
|
LoginType,
|
||||||
Users,
|
Users,
|
||||||
|
changeUser,
|
||||||
sendAllProps,
|
sendAllProps,
|
||||||
} from "../../types/api/index";
|
} from "../../types/api/index";
|
||||||
import { UserInputType } from "../../types/components";
|
import { UserInputType } from "../../types/components";
|
||||||
|
|
@ -427,19 +428,6 @@ export async function addUser(user: UserInputType): Promise<Array<Users>> {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function resetPassword(user_id: string, password: string): Promise<Array<Users>> {
|
|
||||||
try {
|
|
||||||
const res = await api.post(`${BASE_URL_API}users/${user_id}/reset-password`, {password});
|
|
||||||
if (res.status === 200) {
|
|
||||||
return res.data;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.log("Error:", error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getUsersPage(
|
export async function getUsersPage(
|
||||||
skip: number,
|
skip: number,
|
||||||
limit: number
|
limit: number
|
||||||
|
|
@ -470,7 +458,7 @@ export async function deleteUser(user_id: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateUser(user_id: string, user: Users) {
|
export async function updateUser(user_id: string, user: changeUser) {
|
||||||
try {
|
try {
|
||||||
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) {
|
||||||
|
|
|
||||||
|
|
@ -4,20 +4,20 @@ import IconComponent from "../../components/genericIconComponent";
|
||||||
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";
|
||||||
import { CONTROL_RESET_PASSWORD_STATE } from "../../constants/constants";
|
import { CONTROL_PATCH_USER_STATE } from "../../constants/constants";
|
||||||
import { alertContext } from "../../contexts/alertContext";
|
import { alertContext } from "../../contexts/alertContext";
|
||||||
import { AuthContext } from "../../contexts/authContext";
|
import { AuthContext } from "../../contexts/authContext";
|
||||||
import { TabsContext } from "../../contexts/tabsContext";
|
import { TabsContext } from "../../contexts/tabsContext";
|
||||||
import { resetPassword } from "../../controllers/API";
|
import { updateUser } from "../../controllers/API";
|
||||||
import {
|
import {
|
||||||
inputHandlerEventType,
|
inputHandlerEventType,
|
||||||
resetPasswordInputStateType,
|
patchUserInputStateType,
|
||||||
} from "../../types/components";
|
} from "../../types/components";
|
||||||
export default function ProfileSettingsPage(): JSX.Element {
|
export default function ProfileSettingsPage(): JSX.Element {
|
||||||
const { setTabId } = useContext(TabsContext);
|
const { setTabId } = useContext(TabsContext);
|
||||||
|
|
||||||
const [inputState, setInputState] = useState<resetPasswordInputStateType>(
|
const [inputState, setInputState] = useState<patchUserInputStateType>(
|
||||||
CONTROL_RESET_PASSWORD_STATE
|
CONTROL_PATCH_USER_STATE
|
||||||
);
|
);
|
||||||
|
|
||||||
// set null id
|
// set null id
|
||||||
|
|
@ -26,9 +26,9 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
}, []);
|
}, []);
|
||||||
const { setErrorData } = useContext(alertContext);
|
const { setErrorData } = useContext(alertContext);
|
||||||
const { userData } = useContext(AuthContext);
|
const { userData } = useContext(AuthContext);
|
||||||
const { password, cnfPassword } = inputState;
|
const { password, cnfPassword, gradient } = inputState;
|
||||||
|
|
||||||
function changePassword() {
|
function handlePatchUser() {
|
||||||
if (password !== cnfPassword) {
|
if (password !== cnfPassword) {
|
||||||
setErrorData({
|
setErrorData({
|
||||||
title: "Error changing password",
|
title: "Error changing password",
|
||||||
|
|
@ -36,7 +36,8 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
resetPassword(userData!.id, password);
|
|
||||||
|
updateUser(userData!.id, {password, profile_image: gradient});
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleInput({
|
function handleInput({
|
||||||
|
|
@ -62,7 +63,7 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
</span>
|
</span>
|
||||||
<Form.Root
|
<Form.Root
|
||||||
onSubmit={(event) => {
|
onSubmit={(event) => {
|
||||||
changePassword();
|
handlePatchUser();
|
||||||
const data = Object.fromEntries(new FormData(event.currentTarget));
|
const data = Object.fromEntries(new FormData(event.currentTarget));
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
|
|
@ -70,7 +71,7 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
>
|
>
|
||||||
<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="username">
|
<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 <span className="font-medium text-destructive">*</span>
|
||||||
</Form.Label>
|
</Form.Label>
|
||||||
|
|
@ -95,7 +96,7 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
</div>
|
</div>
|
||||||
<div className="mb-3 w-96">
|
<div className="mb-3 w-96">
|
||||||
<Form.Field name="password">
|
<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>
|
<span className="font-medium text-destructive">*</span>
|
||||||
|
|
@ -117,12 +118,34 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
Please confirm your password
|
Please confirm your password
|
||||||
</Form.Message>
|
</Form.Message>
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
|
<Form.Field name="gradient">
|
||||||
|
<Form.Label className="data-[invalid]:label-invalid">
|
||||||
|
Insert Gradient{" "}
|
||||||
|
<span className="font-medium text-destructive">*</span>
|
||||||
|
</Form.Label>
|
||||||
|
|
||||||
|
<InputComponent
|
||||||
|
onChange={(value) => {
|
||||||
|
handleInput({ target: { name: "gradient", value } });
|
||||||
|
}}
|
||||||
|
value={gradient}
|
||||||
|
isForm
|
||||||
|
password={true}
|
||||||
|
required
|
||||||
|
placeholder="Insert Gradient"
|
||||||
|
className="w-full"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Form.Message className="field-invalid" match="valueMissing">
|
||||||
|
Please insert gradient
|
||||||
|
</Form.Message>
|
||||||
|
</Form.Field>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-40">
|
<div className="w-40">
|
||||||
<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">
|
||||||
Reset Password
|
Save
|
||||||
</Button>
|
</Button>
|
||||||
</Form.Submit>
|
</Form.Submit>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,14 @@ export type LoginAuthType = {
|
||||||
token_type?: string;
|
token_type?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type changeUser = {
|
||||||
|
username?: string;
|
||||||
|
is_active?: boolean;
|
||||||
|
is_superuser?: boolean;
|
||||||
|
password?: string;
|
||||||
|
profile_image?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export type Users = {
|
export type Users = {
|
||||||
id: string;
|
id: string;
|
||||||
username: string;
|
username: string;
|
||||||
|
|
|
||||||
|
|
@ -262,9 +262,10 @@ export type loginInputStateType = {
|
||||||
password: string;
|
password: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type resetPasswordInputStateType = {
|
export type patchUserInputStateType = {
|
||||||
password: string;
|
password: string;
|
||||||
cnfPassword: string;
|
cnfPassword: string;
|
||||||
|
gradient: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UserInputType = {
|
export type UserInputType = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue