feat(oms-data-access), feat(return-review): implement task completion in return review

Added updateTaskListItem method to ReturnReviewStore to handle updating
individual task list items. Implemented the UI logic to show/hide the
"Mark as done" button based on completion status and connected the
completeTask method to update the store with the returned result.

Ref: #4942
This commit is contained in:
Nino
2025-04-30 14:56:34 +02:00
parent c98cbd73b1
commit 0d1a65ed4a
3 changed files with 70 additions and 13 deletions

View File

@@ -99,6 +99,56 @@ export const ReturnReviewStore = signalStore(
},
})),
withMethods((store, returnReviewService = inject(ReturnReviewService)) => ({
/**
* Updates a single task list item within a process entity while preserving other properties.
* This method finds the specific item by ID within the entity data array, merges the new
* properties with the existing item, and updates the store state immutably.
*
* @param params - Object containing the parameters for the update
* @param params.processId - The unique identifier for the process entity to update
* @param params.taskListItem - The partial task list item with updated properties that
* should be merged with the existing item. Must include an
* `id` property to identify the target item.
* @returns void - Returns early if the entity doesn't exist or the item isn't found
*
* @example
* // Update the status of a specific task
* returnReviewStore.updateTaskListItem({
* processId: 123,
* taskListItem: { id: 456, status: 'completed' }
* });
*/
updateTaskListItem({
processId,
taskListItem,
}: {
processId: number;
taskListItem: ReceiptItemTaskListItem;
}) {
const entity = store.entityMap()?.[processId];
if (!entity?.data) return;
const itemIndex = entity.data.findIndex(
(item) => item.id === taskListItem.id,
);
if (itemIndex === -1) return;
// Create a new data array with the target item's properties merged
const updatedData = [...entity.data];
updatedData[itemIndex] = {
...updatedData[itemIndex],
...taskListItem,
};
patchState(
store,
updateEntity({
id: processId,
changes: { data: updatedData },
}),
);
},
/**
* Fetches task list items for a specific process ID.
* This is an rxMethod that handles the entire fetch lifecycle:

View File

@@ -7,13 +7,17 @@
<div data-what="review-list" data-which="processing-comment" class="self-start">
{{ processingComment() }}
</div>
<button
type="button"
uiButton
color="secondary"
(click)="markAsDone.emit(this.item().id)"
data-what="button"
data-which="mark-as-done"
>
Als erledigt markieren
</button>
@if (!item()?.completed) {
<button
type="button"
uiButton
color="secondary"
(click)="markAsDone.emit(item().id)"
data-what="button"
data-which="mark-as-done"
>
Als erledigt markieren
</button>
} @else {
Abgeschlossen
}

View File

@@ -54,13 +54,16 @@ export class ReturnReviewComponent {
async completeTask(taskId: number) {
try {
const processId = this.processId();
const result = await firstValueFrom(
this.#returnReviewService.completeTask(taskId),
);
if (result) {
// TODO: Update List
// this.#returnReviewStore.updateTaskListItem(result);
if (result && processId) {
this.#returnReviewStore.updateTaskListItem({
processId,
taskListItem: result,
});
}
} catch (error) {
this.#logger.error('Error completing task', error, {