1
1
import { ActionFunctionArgs , redirect } from "react-router-dom" ;
2
2
3
3
import { TypedAction } from "../../../hooks" ;
4
+ import { CoReview , createCoReview } from "../../../lib/api/coReview" ;
4
5
import {
5
6
Review ,
6
7
ZaakReview ,
@@ -17,22 +18,31 @@ export type DestructionListReviewActionContext = {
17
18
} ;
18
19
19
20
export type ReviewDestructionListAction =
20
- | TypedAction < "APPROVE_LIST" , ReviewDestructionListListApproveActionPayLoad >
21
- | TypedAction < "REJECT_LIST" , ReviewDestructionListListRejectActionPayLoad > ;
21
+ | TypedAction < "APPROVE_LIST" , ReviewDestructionListApproveActionPayLoad >
22
+ | TypedAction < "REJECT_LIST" , ReviewDestructionListRejectActionPayLoad >
23
+ | TypedAction <
24
+ "COMPLETE_CO_REVIEW" ,
25
+ ReviewDestructionListCompleteCoReviewPayload
26
+ > ;
22
27
23
- export type ReviewDestructionListListApproveActionPayLoad = {
28
+ export type ReviewDestructionListApproveActionPayLoad = {
24
29
comment : string ;
25
30
destructionList : string ;
26
31
status : string ;
27
32
} ;
28
33
29
- export type ReviewDestructionListListRejectActionPayLoad = {
34
+ export type ReviewDestructionListRejectActionPayLoad = {
30
35
comment : string ;
31
36
destructionList : string ;
32
37
status : string ;
33
38
zaakReviews ?: ZaakReview [ ] ;
34
39
} ;
35
40
41
+ export type ReviewDestructionListCompleteCoReviewPayload = {
42
+ comment : string ;
43
+ destructionList : string ;
44
+ } ;
45
+
36
46
/**
37
47
* React Router action.
38
48
* @param request
@@ -50,6 +60,8 @@ export const destructionListReviewAction = async ({
50
60
return destructionListApproveListAction ( { request, params } ) ;
51
61
case "REJECT_LIST" :
52
62
return destructionListRejectListAction ( { request, params } ) ;
63
+ case "COMPLETE_CO_REVIEW" :
64
+ return destructionListCompleteCoReviewAction ( { request, params } ) ;
53
65
}
54
66
} ;
55
67
@@ -63,7 +75,7 @@ export async function destructionListApproveListAction({
63
75
} : ActionFunctionArgs ) {
64
76
const { payload } = await request . json ( ) ;
65
77
const { comment, destructionList, status } =
66
- payload as ReviewDestructionListListApproveActionPayLoad ;
78
+ payload as ReviewDestructionListApproveActionPayLoad ;
67
79
68
80
const data : Review = {
69
81
destructionList : destructionList ,
@@ -100,7 +112,7 @@ export async function destructionListRejectListAction({
100
112
} : ActionFunctionArgs ) {
101
113
const { payload } = await request . json ( ) ;
102
114
const { comment, destructionList, status, zaakReviews } =
103
- payload as ReviewDestructionListListRejectActionPayLoad ;
115
+ payload as ReviewDestructionListRejectActionPayLoad ;
104
116
105
117
const data : Review = {
106
118
destructionList : destructionList ,
@@ -127,3 +139,31 @@ export async function destructionListRejectListAction({
127
139
}
128
140
return redirect ( "/" ) ;
129
141
}
142
+
143
+ /**
144
+ * React Router action, user intends to complete a co-review.
145
+ * @param request
146
+ * @param params
147
+ */
148
+ export async function destructionListCompleteCoReviewAction ( {
149
+ request,
150
+ } : ActionFunctionArgs ) {
151
+ const { payload } = await request . json ( ) ;
152
+ const { comment, destructionList } =
153
+ payload as ReviewDestructionListCompleteCoReviewPayload ;
154
+
155
+ const data : CoReview = {
156
+ destructionList : destructionList ,
157
+ listFeedback : comment ,
158
+ } ;
159
+
160
+ try {
161
+ await createCoReview ( data ) ;
162
+ } catch ( e : unknown ) {
163
+ if ( e instanceof Response ) {
164
+ return await ( e as Response ) . json ( ) ;
165
+ }
166
+ throw e ;
167
+ }
168
+ return redirect ( "/" ) ;
169
+ }
0 commit comments