|
1 | 1 | // TaskDetails.tsx - Merged TSX + Styles |
2 | 2 |
|
3 | | -import { HumanFeedbackStatus, Step, TaskDetailsProps } from "@/models"; |
| 3 | +import { HumanFeedbackStatus, Step as OriginalStep, TaskDetailsProps } from "@/models"; |
| 4 | + |
| 5 | +// Extend Step to include _isActionLoading |
| 6 | +type Step = OriginalStep & { _isActionLoading?: boolean }; |
4 | 7 | import { |
5 | 8 | Text, |
6 | 9 | Avatar, |
@@ -28,7 +31,7 @@ const TaskDetails: React.FC<TaskDetailsProps> = ({ |
28 | 31 | loading, |
29 | 32 | OnApproveStep, |
30 | 33 | }) => { |
31 | | - const [steps, setSteps] = useState(planData.steps || []); |
| 34 | + const [steps, setSteps] = useState<Step[]>(planData.steps || []); |
32 | 35 | const [completedCount, setCompletedCount] = useState( |
33 | 36 | planData?.plan.completed || 0 |
34 | 37 | ); |
@@ -146,45 +149,94 @@ const TaskDetails: React.FC<TaskDetailsProps> = ({ |
146 | 149 | <Caption1>{functionOrDetails}</Caption1> |
147 | 150 | )} |
148 | 151 | </Body1> |
149 | | - <div className="task-details-action-buttons"> |
| 152 | + <div className="task-details-action-buttons"> |
150 | 153 | {step.human_approval_status !== "accepted" && |
151 | 154 | step.human_approval_status !== "rejected" && ( |
152 | | - <> <Tooltip relationship="label" content={canInteract?"Approve":"You must first provide feedback to the planner"}> |
153 | | - <Button |
154 | | - icon={<Checkmark20Regular />} |
155 | | - appearance="subtle" |
156 | | - onClick={ |
157 | | - canInteract |
158 | | - ? () => preOnApproved(step) |
159 | | - : undefined |
160 | | - } |
161 | | - className={ |
162 | | - canInteract |
163 | | - ? "task-details-action-button" |
164 | | - : "task-details-action-button-disabled" |
| 155 | + <> |
| 156 | + <Tooltip relationship="label" content={canInteract ? "Approve" : "You must first provide feedback to the planner"}> |
| 157 | + <Button |
| 158 | + icon={<Checkmark20Regular />} |
| 159 | + appearance="subtle" |
| 160 | + onClick={ |
| 161 | + canInteract |
| 162 | + ? async (e) => { |
| 163 | + // Disable buttons for this step |
| 164 | + setSteps((prev) => |
| 165 | + prev.map((s) => |
| 166 | + s.id === step.id |
| 167 | + ? { ...s, _isActionLoading: true } |
| 168 | + : s |
| 169 | + ) |
| 170 | + ); |
| 171 | + try { |
| 172 | + await preOnApproved(step); |
| 173 | + } finally { |
| 174 | + // Remove loading state after API call |
| 175 | + setSteps((prev) => |
| 176 | + prev.map((s) => |
| 177 | + s.id === step.id |
| 178 | + ? { ...s, _isActionLoading: false } |
| 179 | + : s |
| 180 | + ) |
| 181 | + ); |
| 182 | + } |
165 | 183 | } |
166 | | - /> |
| 184 | + : undefined |
| 185 | + } |
| 186 | + disabled={ |
| 187 | + !canInteract || |
| 188 | + !!step._isActionLoading |
| 189 | + } |
| 190 | + className={ |
| 191 | + canInteract |
| 192 | + ? "task-details-action-button" |
| 193 | + : "task-details-action-button-disabled" |
| 194 | + } |
| 195 | + /> |
167 | 196 | </Tooltip> |
168 | 197 |
|
169 | | - <Tooltip relationship="label" content={canInteract?"Reject":"You must first provide feedback to the planner"}> |
170 | | - <Button |
171 | | - icon={<Dismiss20Regular />} |
172 | | - appearance="subtle" |
173 | | - onClick={ |
174 | | - canInteract |
175 | | - ? () => preOnRejected(step) |
176 | | - : undefined |
177 | | - } |
178 | | - className={ |
179 | | - canInteract |
180 | | - ? "task-details-action-button" |
181 | | - : "task-details-action-button-disabled" |
| 198 | + <Tooltip relationship="label" content={canInteract ? "Reject" : "You must first provide feedback to the planner"}> |
| 199 | + <Button |
| 200 | + icon={<Dismiss20Regular />} |
| 201 | + appearance="subtle" |
| 202 | + onClick={ |
| 203 | + canInteract |
| 204 | + ? async (e) => { |
| 205 | + setSteps((prev) => |
| 206 | + prev.map((s) => |
| 207 | + s.id === step.id |
| 208 | + ? { ...s, _isActionLoading: true } |
| 209 | + : s |
| 210 | + ) |
| 211 | + ); |
| 212 | + try { |
| 213 | + await preOnRejected(step); |
| 214 | + } finally { |
| 215 | + setSteps((prev) => |
| 216 | + prev.map((s) => |
| 217 | + s.id === step.id |
| 218 | + ? { ...s, _isActionLoading: false } |
| 219 | + : s |
| 220 | + ) |
| 221 | + ); |
182 | 222 | } |
183 | | - /> |
184 | | - </Tooltip></> |
185 | | - |
| 223 | + } |
| 224 | + : undefined |
| 225 | + } |
| 226 | + disabled={ |
| 227 | + !canInteract || |
| 228 | + !!step._isActionLoading |
| 229 | + } |
| 230 | + className={ |
| 231 | + canInteract |
| 232 | + ? "task-details-action-button" |
| 233 | + : "task-details-action-button-disabled" |
| 234 | + } |
| 235 | + /> |
| 236 | + </Tooltip> |
| 237 | + </> |
186 | 238 | )} |
187 | | - </div> |
| 239 | + </div> |
188 | 240 | </div> |
189 | 241 | </div> |
190 | 242 | ); |
|
0 commit comments