File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed
apps/question-service/src/app Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ import {
32
32
Question ,
33
33
CreateQuestion ,
34
34
NewQuestion ,
35
+ EditQuestion ,
35
36
} from "./services/question" ;
36
37
import {
37
38
CategoriesOption ,
@@ -137,6 +138,22 @@ export default function Home() {
137
138
}
138
139
} ;
139
140
141
+ const handleEditQuestion = async (
142
+ values : NewQuestion ,
143
+ index : number ,
144
+ docRefId : string
145
+ ) => {
146
+ try {
147
+ const editedQuestion = await EditQuestion ( values , docRefId ) ;
148
+ // Reset form or update UI as needed
149
+ handleModalClose ( index ) ;
150
+ editForm . resetFields ( ) ;
151
+ success ( "Problem Updated!" ) ;
152
+ } catch ( err : any ) {
153
+ error ( err . message ) ;
154
+ }
155
+ } ;
156
+
140
157
const handleCreateQuestion = async ( values : NewQuestion ) => {
141
158
try {
142
159
const createdQuestion = await CreateQuestion ( values ) ;
@@ -278,7 +295,7 @@ export default function Home() {
278
295
{ ...layout }
279
296
form = { editForm }
280
297
onFinish = { ( values ) => {
281
- // handleEditQuestion(values); TODO!!! (SEAN) follow the create concept and display error and success values
298
+ handleEditQuestion ( values , index , question . docRefId ) ;
282
299
} }
283
300
>
284
301
< Form . Item
Original file line number Diff line number Diff line change @@ -108,7 +108,29 @@ export const CreateQuestion = async (
108
108
}
109
109
} ;
110
110
111
- // Update single question (TODO: Sean)
111
+ export const EditQuestion = async (
112
+ question : NewQuestion ,
113
+ docRefId : string
114
+ ) : Promise < Question > => {
115
+ const response = await fetch (
116
+ `${ process . env . NEXT_PUBLIC_API_URL } questions/${ docRefId } ` ,
117
+ {
118
+ method : "PUT" ,
119
+ headers : {
120
+ "Content-Type" : "application/json" ,
121
+ } ,
122
+ body : JSON . stringify ( question ) ,
123
+ }
124
+ ) ;
125
+
126
+ if ( response . status === 200 ) {
127
+ return response . json ( ) ;
128
+ } else {
129
+ throw new Error (
130
+ `Error updating question: ${ response . status } ${ response . statusText } `
131
+ ) ;
132
+ }
133
+ } ;
112
134
113
135
// Delete single question (TODO: Ryan)
114
136
export async function DeleteQuestion ( docRef : String ) : Promise < void > {
You can’t perform that action at this time.
0 commit comments