Skip to content

Commit cc1ceac

Browse files
committed
feat(bug fix): add bug fix feature
1 parent 5acf0b1 commit cc1ceac

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

web/src/features/bugFix/BugFix.tsx

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { Stack, HStack, Button } from "@chakra-ui/react";
2+
import { useEffect, useState } from "react";
3+
import { useForm, FormProvider } from "react-hook-form";
4+
import { IoSendOutline } from "react-icons/io5";
5+
import ChatBox from "../../components/internal-ui/ChatBox";
6+
import useGptStore from "../../utils/store";
7+
import { UserType, ENDPOINTS, BugFixFields } from "../constants";
8+
import { BugFixFormData, ApiRequestBugFix } from "../model";
9+
import { v4 as uuid } from "uuid";
10+
import Input from "../../components/internal-ui/Input";
11+
12+
const BugFix = () => {
13+
const formMethods = useForm<BugFixFormData>({
14+
defaultValues: {
15+
minToken: 100,
16+
maxToken: 500,
17+
service: "terraform",
18+
version: "latest",
19+
bugDescription: undefined,
20+
},
21+
mode: "onSubmit",
22+
});
23+
24+
const { handleSubmit } = formMethods;
25+
26+
const messages = useGptStore((s) => s.messages);
27+
const addMessage = useGptStore((s) => s.addMessage);
28+
const [req, setReq] = useState<ApiRequestBugFix | null>(null);
29+
30+
const onSubmit = (data: BugFixFormData) => {
31+
addMessage(UserType.USER, data.bugDescription, uuid());
32+
const request: ApiRequestBugFix = {
33+
min_token: data.minToken,
34+
max_token: data.maxToken,
35+
service: data.service,
36+
bug_description: data.bugDescription,
37+
version: data.version,
38+
requestId: uuid(),
39+
};
40+
if (data.bugDescription) setReq(request);
41+
};
42+
43+
useEffect(() => {
44+
return () => setReq(null);
45+
}, []);
46+
47+
return (
48+
<div>
49+
<FormProvider {...formMethods}>
50+
<form onSubmit={(e) => void handleSubmit(onSubmit)(e)}>
51+
<Stack gap="3" justifyContent="center" alignItems="center">
52+
<div className="flex gap-2">
53+
<Input fieldName={BugFixFields.MIN_TOKEN} label="Min token" />
54+
<Input fieldName={BugFixFields.MAX_TOKEN} label="Max token" />
55+
<Input fieldName={BugFixFields.SERVICE} label="Service" />
56+
<Input fieldName={BugFixFields.VERSION} label="Version" />
57+
</div>
58+
<ChatBox
59+
endpoint={ENDPOINTS.postFix}
60+
request={req}
61+
messageData={messages}
62+
id={req?.requestId ?? ""}
63+
/>
64+
<HStack
65+
mt="3"
66+
alignItems="center"
67+
alignContent="center"
68+
justifyContent="center"
69+
bottom="5"
70+
>
71+
<Input
72+
placeholder="Text"
73+
fieldName={BugFixFields.BUG_DESCRIPTION}
74+
/>
75+
<Button
76+
type="submit"
77+
bg="orange.800"
78+
disabled={
79+
formMethods.getFieldState(BugFixFields.BUG_DESCRIPTION)
80+
.invalid
81+
}
82+
>
83+
<IoSendOutline />
84+
</Button>
85+
</HStack>
86+
</Stack>
87+
</form>
88+
</FormProvider>
89+
</div>
90+
);
91+
};
92+
93+
export default BugFix;

0 commit comments

Comments
 (0)