Skip to content

Commit

Permalink
new case event: decision reviewed
Browse files Browse the repository at this point in the history
fix

Update packages/marble-api/openapis/marblecore-api.yaml

Co-authored-by: Thomas Lathuiliere <40292402+balzdur@users.noreply.github.com>

fix: use reviewed_by

fix centering

fix size of box
  • Loading branch information
Pascal-Delange committed Sep 10, 2024
1 parent 306e431 commit 2f0f2f5
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 6 deletions.
4 changes: 4 additions & 0 deletions packages/app-builder/public/locales/en/cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,18 @@
"case_detail.history.event_title.tags_updated": "Tags updated",
"case_detail.history.event_title.inbox_changed": "Inbox changed",
"case_detail.history.event_title.rule_snooze_created": "Rule snooze created",
"case_detail.history.event_title.decision_reviewed": "Decision reviewed",
"case_detail.history.event_title.status_updated": "New status: <Status>{{status}}</Status>",
"case_detail.history.event_title.file_added": "File added: <Name>{{name}}</Name>",
"case_detail.history.event_detail.added_by": "Added by: <Avatar/> <User>{{user}}</User>",
"case_detail.history.event_detail.added_by_workflow": "Added by workflow",
"case_detail.history.event_detail.edited_by": "Edited by: <Avatar/> <User>{{user}}</User>",
"case_detail.history.event_detail.edited_by_workflow": "Edited by workflow",
"case_detail.history.event_detail.reviewed_by": "Reviewed by: <Avatar/> <User>{{user}}</User>",
"case_detail.history.event_detail.case_tags.new": "New tags: <CaseTags/>",
"case_detail.history.event_detail.case_tags.none": "removed all tags",
"case_detail.history.event_detail.decision_reviewed.review_comment": "Review comment",
"case_detail.history.event_detail.decision_reviewed.final_status": "Final status",
"case_detail.history.event_detail.rule_snooze_created.pivot_value": "pivot value",
"case_detail.history.event_detail.rule_snooze_created.created_from_decision": "decision",
"case_detail.history.event_detail.rule_snooze_created.decision_detail": "decision detail",
Expand Down
77 changes: 74 additions & 3 deletions packages/app-builder/src/components/Cases/CaseEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
type CaseEvent,
type CaseTagsUpdatedEvent,
type CommentAddedEvent,
type RuleSnoozeCreated,
type DecisionReviewedEvent,
type RuleSnoozeCreatedEvent,
} from '@app-builder/models/cases';
import { useGetRuleSnoozeFetcher } from '@app-builder/routes/ressources+/rule-snoozes+/read.$ruleSnoozeId';
import { useOrganizationUsers } from '@app-builder/services/organization/organization-users';
Expand All @@ -23,6 +24,7 @@ import { assertNever } from 'typescript-utils';
import { Avatar, CollapsibleV2 } from 'ui-design-system';
import { Icon, type IconName } from 'ui-icons';

import { Outcome } from '../Decisions/Outcome';
import { Spinner } from '../Spinner';
import { casesI18n } from './cases-i18n';
import { caseStatusMapping, caseStatusVariants } from './CaseStatus';
Expand Down Expand Up @@ -146,6 +148,13 @@ export function getEventIcon(event: CaseEvent) {
icon="snooze"
/>
);
case 'decision_reviewed':
return (
<EventIcon
className="border-grey-10 bg-grey-00 text-grey-100 border"
icon="case-manager"
/>
);
default:
assertNever('[CaseEvent] unknown event:', eventType);
}
Expand All @@ -156,6 +165,7 @@ export function getDefaultOpen(event: CaseEvent) {
switch (eventType) {
case 'comment_added':
case 'rule_snooze_created':
case 'decision_reviewed':
return true;
default:
return false;
Expand Down Expand Up @@ -279,6 +289,12 @@ export function getEventTitle(
{t('cases:case_detail.history.event_title.rule_snooze_created')}
</span>
);
case 'decision_reviewed':
return (
<span className="text-s text-grey-100 font-semibold first-letter:capitalize">
{t('cases:case_detail.history.event_title.decision_reviewed')}
</span>
);
default:
assertNever('[CaseEvent] unknown event:', eventType);
}
Expand All @@ -289,7 +305,7 @@ function Author({
type,
}: {
userId: string;
type: 'added_by' | 'edited_by';
type: 'added_by' | 'edited_by' | 'reviewed_by';
}) {
const { t } = useTranslation(casesI18n);
const { getOrgUserById } = useOrganizationUsers();
Expand Down Expand Up @@ -351,6 +367,9 @@ export function getEventDetail(event: CaseEvent) {
case 'rule_snooze_created': {
return <RuleSnoozeCreatedDetail event={event} />;
}
case 'decision_reviewed': {
return <DecisionReviewedEventDetail event={event} />;
}
case 'decision_added': {
if (!event.userId) {
return <ByWorkflow type="added_by_workflow" />;
Expand Down Expand Up @@ -383,6 +402,58 @@ function CommentAddedEventDetail({ event }: { event: CommentAddedEvent }) {
);
}

function DecisionReviewedEventDetail({
event,
}: {
event: DecisionReviewedEvent;
}) {
const { t } = useTranslation(casesI18n);

return (
<div className="flex flex-col gap-2">
<Author userId={event.userId} type="reviewed_by" />
<div className="grid w-full grid-cols-[max-content_1fr] items-center gap-2">
<span className="text-grey-100 text-s font-semibold first-letter:capitalize">
{t(
'cases:case_detail.history.event_detail.decision_reviewed.review_comment',
)}
</span>
<span className="text-s text-grey-100 whitespace-break-spaces font-normal">
{event.reviewComment}
</span>
<span className="text-grey-100 text-s font-semibold first-letter:capitalize">
{t(
'cases:case_detail.history.event_detail.decision_reviewed.final_status',
)}
</span>
<Outcome
border="square"
size="small"
outcome={event.finalStatus}
className="w-fit"
/>
<span className="text-grey-100 text-s font-semibold first-letter:capitalize">
{t(
'cases:case_detail.history.event_detail.rule_snooze_created.created_from_decision',
)}
</span>
<span className="text-grey-100 text-s">
<Link
className="hover:text-purple-120 focus:text-purple-120 relative font-semibold text-purple-100 hover:underline focus:underline"
to={getRoute('/decisions/:decisionId', {
decisionId: fromUUID(event.decisionId),
})}
>
{t(
'cases:case_detail.history.event_detail.rule_snooze_created.decision_detail',
)}
</Link>
</span>
</div>
</div>
);
}

function TagsUpdatedEventDetail({ event }: { event: CaseTagsUpdatedEvent }) {
const { t } = useTranslation(casesI18n);
return (
Expand All @@ -407,7 +478,7 @@ function TagsUpdatedEventDetail({ event }: { event: CaseTagsUpdatedEvent }) {
);
}

function RuleSnoozeCreatedDetail({ event }: { event: RuleSnoozeCreated }) {
function RuleSnoozeCreatedDetail({ event }: { event: RuleSnoozeCreatedEvent }) {
return (
<div className="flex flex-col gap-2">
<Author userId={event.userId} type="added_by" />
Expand Down
22 changes: 20 additions & 2 deletions packages/app-builder/src/models/cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,19 @@ export interface InboxChangedEvent extends CaseEventBase {
newInboxId: string;
userId: string;
}
export interface RuleSnoozeCreated extends CaseEventBase {
export interface RuleSnoozeCreatedEvent extends CaseEventBase {
eventType: 'rule_snooze_created';
ruleSnoozeId: string;
userId: string;
comment: string;
}
export interface DecisionReviewedEvent extends CaseEventBase {
eventType: 'decision_reviewed';
userId: string;
reviewComment: string;
finalStatus: 'approve' | 'decline';
decisionId: string;
}

export type CaseEvent =
| CaseCreatedEvent
Expand All @@ -137,7 +144,8 @@ export type CaseEvent =
| CaseTagsUpdatedEvent
| FileAddedEvent
| InboxChangedEvent
| RuleSnoozeCreated;
| RuleSnoozeCreatedEvent
| DecisionReviewedEvent;

export function adaptCaseEventDto(caseEventDto: CaseEventDto): CaseEvent {
const caseEvent = {
Expand Down Expand Up @@ -221,6 +229,16 @@ export function adaptCaseEventDto(caseEventDto: CaseEventDto): CaseEvent {
comment: caseEventDto.additional_note,
};
}
case 'decision_reviewed': {
return {
...caseEvent,
decisionId: caseEventDto.resource_id,
eventType: 'decision_reviewed',
reviewComment: caseEventDto.additional_note,
finalStatus: caseEventDto.new_value,
userId: caseEventDto.user_id,
};
}
default:
assertNever('[CaseEventDto] unknown event:', event_type);
}
Expand Down
35 changes: 35 additions & 0 deletions packages/marble-api/openapis/marblecore-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4058,6 +4058,7 @@ components:
file_added: '#/components/schemas/FileAddedEventDto'
inbox_changed: '#/components/schemas/InboxChangedEventDto'
rule_snooze_created: '#/components/schemas/RuleSnoozeCreatedDto'
decision_reviewed: '#/components/schemas/DecisionReviewedEventDto'
required:
- id
- case_id
Expand Down Expand Up @@ -4274,6 +4275,40 @@ components:
user_id:
type: string
format: uuid
DecisionReviewedEventDto:
allOf:
- $ref: '#/components/schemas/CaseEventDto'
- type: object
required:
- additional_note
- new_value
- previous_value
- resource_id
- resource_type
- user_id
properties:
additional_note:
type: string
description: The note added by the user to justify the review
new_value:
type: string
format: uuid
description: The new review_status of the decision
enum: ['approve', 'decline']
previous_value:
type: string
format: uuid
description: The previous review_status of the decision
resource_id:
type: string
format: uuid
description: The id of the decision being reviewed
resource_type:
type: string
enum: ['decision']
user_id:
type: string
format: uuid
UpdateCaseBodyDto:
type: object
properties:
Expand Down
17 changes: 16 additions & 1 deletion packages/marble-api/src/generated/marblecore-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,22 @@ export type RuleSnoozeCreatedDto = {
resource_type: string;
user_id: string;
};
export type CaseEventDto = CaseCreatedEventDto | CaseStatusUpdatedEventDto | DecisionAddedEventDto | CommentAddedEventDto | NameUpdatedEventDto | CaseTagsUpdatedEventDto | FileAddedEventDto | InboxChangedEventDto | RuleSnoozeCreatedDto;
export type DecisionReviewedEventDto = {
event_type: "decision_reviewed";
} & CaseEventDtoBase & {
/** The note added by the user to justify the review */
additional_note: string;
/** The new review_status of the decision */
new_value: "approve" | "decline";
/** The previous review_status of the decision */
previous_value: string;
/** The id of the decision being reviewed */
resource_id: string;
/** Must take the value 'decision' */
resource_type: string;
user_id: string;
};
export type CaseEventDto = CaseCreatedEventDto | CaseStatusUpdatedEventDto | DecisionAddedEventDto | CommentAddedEventDto | NameUpdatedEventDto | CaseTagsUpdatedEventDto | FileAddedEventDto | InboxChangedEventDto | RuleSnoozeCreatedDto | DecisionReviewedEventDto;
export type CaseFileDto = {
id: string;
case_id: string;
Expand Down

0 comments on commit 2f0f2f5

Please sign in to comment.