Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3dd3859

Browse files
chore: add task feedback dialog component (#20252)
Related to#20214This PR aims to add only the FE component for capturing user feedbackfrom tasks. Once the BE work is completed (in a separate PR), thiscomponent will be triggered after a task is deleted.The goal is to develop this feature in parallel.**Screenshot:**<img width="1206" height="727" alt="Screenshot 2025-10-09 at 14 31 53"src="https://github.com/user-attachments/assets/1f92026c-8f05-4535-bbd6-85c4b107c037"/>
1 parent9f22937 commit3dd3859

File tree

4 files changed

+284
-1
lines changed

4 files changed

+284
-1
lines changed

‎site/src/api/api.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,6 +2669,13 @@ class ApiMethods {
26692669
//
26702670
// All methods must be defined with arrow function syntax. See the docstring
26712671
// above the ApiMethods class for a full explanation.
2672+
2673+
exporttypeTaskFeedbackRating="good"|"okay"|"bad";
2674+
2675+
exporttypeCreateTaskFeedbackRequest={
2676+
rate:TaskFeedbackRating;
2677+
comment?:string;
2678+
};
26722679
classExperimentalApiMethods{
26732680
constructor(protectedreadonlyaxios:AxiosInstance){}
26742681

@@ -2732,6 +2739,15 @@ class ExperimentalApiMethods {
27322739
deleteTask=async(user:string,id:string):Promise<void>=>{
27332740
awaitthis.axios.delete(`/api/experimental/tasks/${user}/${id}`);
27342741
};
2742+
2743+
createTaskFeedback=async(
2744+
_taskId:string,
2745+
_req:CreateTaskFeedbackRequest,
2746+
)=>{
2747+
returnnewPromise<void>((res)=>{
2748+
setTimeout(()=>res(),500);
2749+
});
2750+
};
27352751
}
27362752

27372753
// This is a hard coded CSRF token/cookie pair for local development. In prod,

‎site/src/components/Dialog/Dialog.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const DialogTrigger = DialogPrimitive.Trigger;
1919

2020
constDialogPortal=DialogPrimitive.Portal;
2121

22-
const_DialogClose=DialogPrimitive.Close;
22+
exportconstDialogClose=DialogPrimitive.Close;
2323

2424
constDialogOverlay=forwardRef<
2525
ElementRef<typeofDialogPrimitive.Overlay>,
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import{MockTask,mockApiError}from"testHelpers/entities";
2+
import{withGlobalSnackbar}from"testHelpers/storybook";
3+
importtype{Meta,StoryObj}from"@storybook/react-vite";
4+
import{API}from"api/api";
5+
import{expect,spyOn,userEvent,within}from"storybook/test";
6+
import{TaskFeedbackDialog}from"./TaskFeedbackDialog";
7+
8+
constmeta:Meta<typeofTaskFeedbackDialog>={
9+
title:"modules/tasks/TaskFeedbackDialog",
10+
component:TaskFeedbackDialog,
11+
args:{
12+
taskId:MockTask.id,
13+
open:true,
14+
},
15+
};
16+
17+
exportdefaultmeta;
18+
typeStory=StoryObj<typeofTaskFeedbackDialog>;
19+
20+
exportconstIdle:Story={};
21+
22+
exportconstSubmitting:Story={
23+
beforeEach:async()=>{
24+
spyOn(API.experimental,"createTaskFeedback").mockImplementation(()=>{
25+
returnnewPromise(()=>{});
26+
});
27+
},
28+
play:async({ canvasElement, step})=>{
29+
constbody=within(canvasElement.ownerDocument.body);
30+
31+
step("fill and submit the form",async()=>{
32+
constregularOption=body.getByLabelText(
33+
"It sort of worked, but struggled a lot",
34+
);
35+
userEvent.click(regularOption);
36+
37+
constcommentTextarea=body.getByRole("textbox",{
38+
name:"Additional comments",
39+
});
40+
awaituserEvent.type(commentTextarea,"This is my comment");
41+
42+
constsubmitButton=body.getByRole("button",{
43+
name:"Submit Feedback",
44+
});
45+
awaituserEvent.click(submitButton);
46+
});
47+
},
48+
};
49+
50+
exportconstSuccess:Story={
51+
args:{
52+
open:true,
53+
},
54+
decorators:[withGlobalSnackbar],
55+
beforeEach:async()=>{
56+
spyOn(API.experimental,"createTaskFeedback").mockResolvedValue();
57+
},
58+
play:async({ canvasElement, step})=>{
59+
constbody=within(canvasElement.ownerDocument.body);
60+
61+
step("fill and submit the form",async()=>{
62+
constregularOption=body.getByLabelText(
63+
"It sort of worked, but struggled a lot",
64+
);
65+
userEvent.click(regularOption);
66+
67+
constcommentTextarea=body.getByRole("textbox",{
68+
name:"Additional comments",
69+
});
70+
awaituserEvent.type(commentTextarea,"This is my comment");
71+
72+
constsubmitButton=body.getByRole("button",{
73+
name:"Submit Feedback",
74+
});
75+
awaituserEvent.click(submitButton);
76+
});
77+
78+
step("submitted successfully",async()=>{
79+
awaitbody.findByText("Feedback submitted successfully");
80+
expect(API.experimental.createTaskFeedback).toHaveBeenCalledWith(
81+
MockTask.id,
82+
{
83+
rate:"regular",
84+
comment:"This is my comment",
85+
},
86+
);
87+
});
88+
},
89+
};
90+
91+
exportconstFailure:Story={
92+
beforeEach:async()=>{
93+
spyOn(API.experimental,"createTaskFeedback").mockRejectedValue(
94+
mockApiError({
95+
message:"Failed to submit feedback",
96+
detail:"Server is down",
97+
}),
98+
);
99+
},
100+
play:async({ canvasElement, step})=>{
101+
constbody=within(canvasElement.ownerDocument.body);
102+
103+
step("fill and submit the form",async()=>{
104+
constregularOption=body.getByLabelText(
105+
"It sort of worked, but struggled a lot",
106+
);
107+
userEvent.click(regularOption);
108+
109+
constcommentTextarea=body.getByRole("textbox",{
110+
name:"Additional comments",
111+
});
112+
awaituserEvent.type(commentTextarea,"This is my comment");
113+
114+
constsubmitButton=body.getByRole("button",{
115+
name:"Submit Feedback",
116+
});
117+
awaituserEvent.click(submitButton);
118+
});
119+
},
120+
};
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import{
2+
API,
3+
typeCreateTaskFeedbackRequest,
4+
typeTaskFeedbackRating,
5+
}from"api/api";
6+
import{ErrorAlert}from"components/Alert/ErrorAlert";
7+
import{Button}from"components/Button/Button";
8+
import{
9+
Dialog,
10+
DialogClose,
11+
DialogContent,
12+
DialogDescription,
13+
DialogFooter,
14+
DialogHeader,
15+
DialogTitle,
16+
}from"components/Dialog/Dialog";
17+
importtype{DialogProps}from"components/Dialogs/Dialog";
18+
import{displaySuccess}from"components/GlobalSnackbar/utils";
19+
import{Spinner}from"components/Spinner/Spinner";
20+
import{Textarea}from"components/Textarea/Textarea";
21+
import{useFormik}from"formik";
22+
import{FrownIcon,MehIcon,SmileIcon}from"lucide-react";
23+
importtype{FC,HTMLProps,ReactNode}from"react";
24+
import{useMutation}from"react-query";
25+
26+
typeTaskFeedbackFormValues={
27+
rate:TaskFeedbackRating|null;
28+
comment:string;
29+
};
30+
31+
typeTaskFeedbackDialogProps=DialogProps&{
32+
taskId:string;
33+
};
34+
35+
exportconstTaskFeedbackDialog:FC<TaskFeedbackDialogProps>=({
36+
taskId,
37+
...dialogProps
38+
})=>{
39+
const{
40+
mutate:createFeedback,
41+
error,
42+
isPending,
43+
}=useMutation({
44+
mutationFn:(req:CreateTaskFeedbackRequest)=>
45+
API.experimental.createTaskFeedback(taskId,req),
46+
onSuccess:()=>{
47+
displaySuccess("Feedback submitted successfully");
48+
},
49+
});
50+
51+
constformik=useFormik<TaskFeedbackFormValues>({
52+
initialValues:{
53+
rate:null,
54+
comment:"",
55+
},
56+
onSubmit:(values)=>{
57+
if(values.rate!==null){
58+
createFeedback({
59+
rate:values.rate,
60+
comment:values.comment,
61+
});
62+
}
63+
},
64+
});
65+
66+
constisRateSelected=Boolean(formik.values.rate);
67+
68+
return(
69+
<Dialog{...dialogProps}>
70+
<DialogContent>
71+
<DialogHeader>
72+
<DialogTitle>Task feedback</DialogTitle>
73+
<DialogDescription>
74+
Your feedback is important to us. Please rate your experience with
75+
this task.
76+
</DialogDescription>
77+
</DialogHeader>
78+
79+
<form
80+
id="feedback-form"
81+
onSubmit={formik.handleSubmit}
82+
className="flex flex-col gap-4"
83+
>
84+
{error&&<ErrorAlerterror={error}/>}
85+
86+
<fieldsetclassName="flex flex-col gap-1">
87+
<legendclassName="sr-only">Rate your experience</legend>
88+
<RateOption{...formik.getFieldProps("rate")}value="good">
89+
<SmileIcon/>I achieved my goal
90+
</RateOption>
91+
<RateOption{...formik.getFieldProps("rate")}value="okay">
92+
<MehIcon/>
93+
It sort of worked, but struggled a lot
94+
</RateOption>
95+
<RateOption{...formik.getFieldProps("rate")}value="bad">
96+
<FrownIcon/>
97+
It was a flop
98+
</RateOption>
99+
</fieldset>
100+
101+
<labelclassName="sr-only"htmlFor="comment">
102+
Additional comments
103+
</label>
104+
<Textarea
105+
id="comment"
106+
placeholder="Wanna say something else?..."
107+
className="h-32 resize-none"
108+
{...formik.getFieldProps("comment")}
109+
/>
110+
</form>
111+
112+
<DialogFooter>
113+
<DialogCloseasChild>
114+
<Buttonvariant="outline">Close</Button>
115+
</DialogClose>
116+
<Button
117+
type="submit"
118+
form="feedback-form"
119+
disabled={!isRateSelected||isPending}
120+
>
121+
<Spinnerloading={isPending}/>
122+
Submit Feedback
123+
</Button>
124+
</DialogFooter>
125+
</DialogContent>
126+
</Dialog>
127+
);
128+
};
129+
130+
typeRateOptionProps=HTMLProps<HTMLInputElement>&{
131+
children:ReactNode;
132+
};
133+
134+
constRateOption:FC<RateOptionProps>=({ children, ...inputProps})=>{
135+
return(
136+
<label
137+
className={`
138+
cursor-pointer border border-border border-solid hover:bg-surface-secondary
139+
px-4 py-3 rounded text-sm has-[:checked]:bg-surface-quaternary
140+
flex items-center gap-3 [&_svg]:size-4
141+
`}
142+
>
143+
<inputclassName="hidden"type="radio"{...inputProps}/>
144+
{children}
145+
</label>
146+
);
147+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp