Added Profile settings into General page

This commit is contained in:
Lucas Oliveira 2024-04-30 00:56:53 +02:00
commit ad52526642
2 changed files with 191 additions and 110 deletions

View file

@ -2,7 +2,7 @@ import { gradients } from "../../utils/styleUtils";
export default function GradientChooserComponent({ value, onChange }) { export default function GradientChooserComponent({ value, onChange }) {
return ( return (
<div className="flex flex-wrap items-center justify-center gap-4"> <div className="flex flex-wrap items-center justify-start gap-2">
{gradients.map((gradient, idx) => ( {gradients.map((gradient, idx) => (
<div <div
onClick={() => { onClick={() => {

View file

@ -1,8 +1,10 @@
import { Button } from "../../../../components/ui/button"; import * as Form from "@radix-ui/react-form";
import { cloneDeep } from "lodash";
import { ColDef, ColGroupDef } from "ag-grid-community"; import { useContext, useEffect, useState } from "react";
import { useState } from "react";
import ForwardedIconComponent from "../../../../components/genericIconComponent"; import ForwardedIconComponent from "../../../../components/genericIconComponent";
import GradientChooserComponent from "../../../../components/gradientChooserComponent";
import InputComponent from "../../../../components/inputComponent";
import { Button } from "../../../../components/ui/button";
import { import {
Card, Card,
CardContent, CardContent,
@ -11,71 +13,88 @@ import {
CardHeader, CardHeader,
CardTitle, CardTitle,
} from "../../../../components/ui/card"; } from "../../../../components/ui/card";
import { Checkbox } from "../../../../components/ui/checkbox"; import {
import { Input } from "../../../../components/ui/input"; EDIT_PASSWORD_ALERT_LIST,
EDIT_PASSWORD_ERROR_ALERT,
SAVE_ERROR_ALERT,
SAVE_SUCCESS_ALERT,
} from "../../../../constants/alerts_constants";
import { CONTROL_PATCH_USER_STATE } from "../../../../constants/constants";
import { AuthContext } from "../../../../contexts/authContext";
import { resetPassword, updateUser } from "../../../../controllers/API";
import useAlertStore from "../../../../stores/alertStore";
import useFlowsManagerStore from "../../../../stores/flowsManagerStore";
import {
inputHandlerEventType,
patchUserInputStateType,
} from "../../../../types/components";
import { gradients } from "../../../../utils/styleUtils";
export default function GeneralPage() { export default function GeneralPage() {
// Column Definitions: Defines the columns to be displayed. const setCurrentFlowId = useFlowsManagerStore(
const [colDefs, setColDefs] = useState<(ColDef<any> | ColGroupDef<any>)[]>([ (state) => state.setCurrentFlowId
{ headerName: "Variable Name", field: "name", flex: 1 }, //This column will be twice as wide as the others );
{
field: "type",
cellEditor: "agSelectCellEditor",
cellEditorParams: {
values: ["Prompt", "Credential"],
valueListGap: 10,
},
flex: 1,
editable: true,
},
{
field: "value",
cellEditor: "agLargeTextCellEditor",
cellEditorPopup: true,
flex: 2,
editable: true,
},
{
headerName: "Apply To Fields",
field: "defaultFields",
flex: 1,
editable: true,
},
]);
const [rowData, setRowData] = useState([ const [inputState, setInputState] = useState<patchUserInputStateType>(
{ CONTROL_PATCH_USER_STATE
name: "OpenAI Key", );
type: "Credential",
value: "apijpioj09u302j0982ejf",
defaultFields: "Open AI API Key",
},
{
name: "Prompt",
type: "Prompt",
value: `Answer user's questions based on the document below:
--- const { autoLogin } = useContext(AuthContext);
{Document} // set null id
useEffect(() => {
setCurrentFlowId("");
}, []);
const setSuccessData = useAlertStore((state) => state.setSuccessData);
const setErrorData = useAlertStore((state) => state.setErrorData);
const { userData, setUserData } = useContext(AuthContext);
const { password, cnfPassword, gradient } = inputState;
--- async function handlePatchPassword() {
if (password !== cnfPassword) {
setErrorData({
title: EDIT_PASSWORD_ERROR_ALERT,
list: [EDIT_PASSWORD_ALERT_LIST],
});
return;
}
try {
if (password !== "") await resetPassword(userData!.id, { password });
handleInput({ target: { name: "password", value: "" } });
handleInput({ target: { name: "cnfPassword", value: "" } });
setSuccessData({ title: SAVE_SUCCESS_ALERT });
} catch (error) {
setErrorData({
title: SAVE_ERROR_ALERT,
list: [(error as any).response.data.detail],
});
}
}
Question: async function handlePatchGradient() {
{Question} try {
if (gradient !== "")
await updateUser(userData!.id, { profile_image: gradient });
if (gradient !== "") {
let newUserData = cloneDeep(userData);
newUserData!.profile_image = gradient;
Answer: setUserData(newUserData);
`, }
defaultFields: ["Prompt"], setSuccessData({ title: SAVE_SUCCESS_ALERT });
}, } catch (error) {
{ setErrorData({
name: "Azure Key", title: SAVE_ERROR_ALERT,
type: "Credential", list: [(error as any).response.data.detail],
value: "awowkdenvoaimojndofunoweoij0293u0n2e08n23", });
defaultFields: ["Azure API Key"], }
}, }
]);
function handleInput({
target: { name, value },
}: inputHandlerEventType): void {
setInputState((prev) => ({ ...prev, [name]: value }));
}
return ( return (
<div className="flex h-full w-full flex-col gap-6"> <div className="flex h-full w-full flex-col gap-6">
<div className="flex w-full items-center justify-between gap-4 space-y-0.5"> <div className="flex w-full items-center justify-between gap-4 space-y-0.5">
@ -94,51 +113,113 @@ export default function GeneralPage() {
</div> </div>
<div className="grid gap-6"> <div className="grid gap-6">
{!autoLogin && (
<>
<Form.Root
onSubmit={(event) => {
handlePatchGradient();
event.preventDefault();
}}
>
<Card x-chunk="dashboard-04-chunk-1"> <Card x-chunk="dashboard-04-chunk-1">
<CardHeader> <CardHeader>
<CardTitle>Store Name</CardTitle> <CardTitle>Profile Gradient</CardTitle>
<CardDescription> <CardDescription>
Used to identify your store in the marketplace. Choose the gradient that appears as your profile picture.
</CardDescription> </CardDescription>
</CardHeader> </CardHeader>
<CardContent> <CardContent>
<form> <div className="py-2">
<Input placeholder="Store Name" /> <GradientChooserComponent
</form> value={
gradient == ""
? userData?.profile_image ??
gradients[
parseInt(userData?.id ?? "", 30) %
gradients.length
]
: gradient
}
onChange={(value) => {
handleInput({ target: { name: "gradient", value } });
}}
/>
</div>
</CardContent> </CardContent>
<CardFooter className="border-t px-6 py-4"> <CardFooter className="border-t px-6 py-4">
<Button>Save</Button> <Form.Submit asChild>
<Button type="submit">Save</Button>
</Form.Submit>
</CardFooter> </CardFooter>
</Card> </Card>
</Form.Root>
<Form.Root
onSubmit={(event) => {
handlePatchPassword();
event.preventDefault();
}}
>
<Card x-chunk="dashboard-04-chunk-2"> <Card x-chunk="dashboard-04-chunk-2">
<CardHeader> <CardHeader>
<CardTitle>Plugins Directory</CardTitle> <CardTitle>Password</CardTitle>
<CardDescription> <CardDescription>
The directory within your project, in which your plugins are Type your new password and confirm it.
located.
</CardDescription> </CardDescription>
</CardHeader> </CardHeader>
<CardContent> <CardContent>
<form className="flex flex-col gap-4"> <div className="flex w-full gap-4">
<Input <Form.Field name="password" className="w-full">
placeholder="Project Name" <InputComponent
defaultValue="/content/plugins" id="pasword"
onChange={(value) => {
handleInput({ target: { name: "password", value } });
}}
value={password}
isForm
password={true}
placeholder="Password"
className="w-full"
/> />
<div className="flex items-center space-x-2"> <Form.Message
<Checkbox id="include" defaultChecked /> match="valueMissing"
<label className="field-invalid"
htmlFor="include"
className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
> >
Allow administrators to change the directory. Please enter your password
</label> </Form.Message>
</Form.Field>
<Form.Field name="cnfPassword" className="w-full">
<InputComponent
id="cnfPassword"
onChange={(value) => {
handleInput({
target: { name: "cnfPassword", value },
});
}}
value={cnfPassword}
isForm
password={true}
placeholder="Confirm Password"
className="w-full"
/>
<Form.Message
className="field-invalid"
match="valueMissing"
>
Please confirm your password
</Form.Message>
</Form.Field>
</div> </div>
</form>
</CardContent> </CardContent>
<CardFooter className="border-t px-6 py-4"> <CardFooter className="border-t px-6 py-4">
<Button>Save</Button> <Form.Submit asChild>
<Button type="submit">Save</Button>
</Form.Submit>
</CardFooter> </CardFooter>
</Card> </Card>
</Form.Root>
</>
)}
</div> </div>
</div> </div>
); );