-
Notifications
You must be signed in to change notification settings - Fork 0
TEC-25: QuickWerk Phase 4 operator dispute lifecycle (end-to-end) #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c3e5682
feat(disputes): add operator lifecycle transitions end-to-end
ca9eb51
TEC-25: address CodeRabbit dispute lifecycle review
75c0acf
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] 6852f3d
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] d00f573
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] aff91ff
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| /// <reference types="next" /> | ||
| /// <reference types="next/image-types/global" /> | ||
| import "./.next/types/routes.d.ts"; | ||
|
|
||
| // NOTE: This file should not be edited | ||
| // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. | ||
| // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 103 additions & 3 deletions
106
apps/admin-web/src/features/disputes/dispute-queue-state.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,112 @@ | ||
| import type { DisputeRecord } from '@quickwerk/domain'; | ||
| import { | ||
| disputeOperatorActionTransitions, | ||
| type DisputeOperatorActionType, | ||
| type DisputeRecord, | ||
| } from '@quickwerk/domain'; | ||
|
|
||
| export type DisputeQueueActionType = DisputeOperatorActionType; | ||
|
|
||
| export type DisputeQueueAction = | ||
| | { status: 'idle' } | ||
| | { status: 'transitioning'; disputeId: string; actionType: DisputeQueueActionType } | ||
| | { status: 'done'; disputeId: string; actionType: DisputeQueueActionType } | ||
| | { status: 'error'; disputeId: string; actionType: DisputeQueueActionType; errorMessage: string }; | ||
|
|
||
| export type DisputeQueueState = | ||
| | { status: 'loading' } | ||
| | { status: 'empty' } | ||
| | { status: 'loaded'; disputes: DisputeRecord[] } | ||
| | { status: 'loaded'; disputes: DisputeRecord[]; queueAction: DisputeQueueAction } | ||
| | { status: 'error'; errorMessage: string }; | ||
|
|
||
| export const createLoadingState = (): DisputeQueueState => ({ status: 'loading' }); | ||
| export const createEmptyState = (): DisputeQueueState => ({ status: 'empty' }); | ||
| export const createLoadedState = (disputes: DisputeRecord[]): DisputeQueueState => ({ status: 'loaded', disputes }); | ||
| export const createLoadedState = (disputes: DisputeRecord[]): DisputeQueueState => ({ | ||
| status: 'loaded', | ||
| disputes, | ||
| queueAction: { status: 'idle' }, | ||
| }); | ||
| export const createErrorState = (errorMessage: string): DisputeQueueState => ({ status: 'error', errorMessage }); | ||
|
|
||
| export const beginOptimisticDisputeTransition = ( | ||
| state: DisputeQueueState, | ||
| disputeId: string, | ||
| actionType: DisputeQueueActionType, | ||
| ): DisputeQueueState => { | ||
| if (state.status !== 'loaded') { | ||
| return state; | ||
| } | ||
|
|
||
| if (state.queueAction?.status === 'transitioning') { | ||
| return state; | ||
| } | ||
|
|
||
| const dispute = state.disputes.find((d) => d.disputeId === disputeId); | ||
| if (!dispute) { | ||
| return state; | ||
| } | ||
|
|
||
| const nextStatus = disputeOperatorActionTransitions[actionType]; | ||
| if (!nextStatus || nextStatus === dispute.status) { | ||
| return state; | ||
| } | ||
|
|
||
| const disputes = state.disputes.map((d) => { | ||
| if (d.disputeId !== disputeId) { | ||
| return d; | ||
| } | ||
|
|
||
| return { ...d, status: nextStatus }; | ||
| }); | ||
|
|
||
| return { | ||
| ...state, | ||
| disputes, | ||
| queueAction: { status: 'transitioning', disputeId, actionType }, | ||
| }; | ||
| }; | ||
|
|
||
| export const applyDisputeTransitionSuccess = ( | ||
| state: DisputeQueueState, | ||
| dispute: DisputeRecord, | ||
| actionType: DisputeQueueActionType, | ||
| ): DisputeQueueState => { | ||
| if (state.status !== 'loaded') { | ||
| return state; | ||
| } | ||
|
|
||
| if (dispute.status === 'resolved' || dispute.status === 'closed') { | ||
| const remaining = state.disputes.filter((item) => item.disputeId !== dispute.disputeId); | ||
| if (remaining.length === 0) { | ||
| return createEmptyState(); | ||
| } | ||
|
|
||
| return { | ||
| status: 'loaded', | ||
| disputes: remaining, | ||
| queueAction: { status: 'done', disputeId: dispute.disputeId, actionType }, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| status: 'loaded', | ||
| disputes: state.disputes.map((item) => (item.disputeId === dispute.disputeId ? dispute : item)), | ||
| queueAction: { status: 'done', disputeId: dispute.disputeId, actionType }, | ||
| }; | ||
| }; | ||
|
|
||
| export const rollbackDisputeTransition = ( | ||
| state: DisputeQueueState, | ||
| previousState: DisputeQueueState, | ||
| disputeId: string, | ||
| actionType: DisputeQueueActionType, | ||
| errorMessage: string, | ||
| ): DisputeQueueState => { | ||
| if (previousState.status !== 'loaded') { | ||
| return createErrorState(errorMessage); | ||
| } | ||
|
|
||
| return { | ||
| ...previousState, | ||
| queueAction: { status: 'error', disputeId, actionType, errorMessage }, | ||
| }; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| { | ||
| "extends": "../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "rootDir": "src" | ||
| }, | ||
| "compilerOptions": {}, | ||
| "include": ["src/**/*.ts", ".next/types/**/*.ts"] | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.