-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(*): wip - alerts decision changes * feat(*): added the functionality of making a decision * feat(workflows-service): now assigning alerts on decision * fix(backoffice-v2): coming soon decisions are now disabled * refactor(backoffice-v2): revert decision now moves an alert to new/triggered * refactor(backoffice-v2): renamed toast function * style(schema.prisma): fixed format * refactor(backoffice-v2): removed false positive mapping * fix(backoffice-v2): fixed revert decision toast * refactor(backoffice-v2): addressed PR comments * refactor(backoffice-v2): addressed PR comments for toasts string literals
- Loading branch information
Showing
21 changed files
with
442 additions
and
93 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
8 changes: 8 additions & 0 deletions
8
apps/backoffice-v2/src/common/utils/to-screaming-snake-case/to-screaming-snake-case.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { isString } from '@/common/utils/is-string/is-string'; | ||
import { snakeCase, toUpperCase } from 'string-ts'; | ||
|
||
export const toScreamingSnakeCase = <TString extends string>(string_: TString) => { | ||
if (!isString(string_)) return string_; | ||
|
||
return toUpperCase(snakeCase(string_)); | ||
}; |
This file contains 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
50 changes: 50 additions & 0 deletions
50
.../alerts/hooks/mutations/useAlertsDecisionByIdsMutation/useAlertsDecisionByIdsMutation.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import toast from 'react-hot-toast'; | ||
import { t } from 'i18next'; | ||
import { AlertState, TAlertState, updateAlertsDecisionByIds } from '@/domains/alerts/fetchers'; | ||
import { TToastKeyWithSuccessAndError } from '@/common/types'; | ||
|
||
const getToastAction = (decision: TAlertState): TToastKeyWithSuccessAndError => { | ||
if (decision === AlertState.REJECTED) { | ||
return 'reject_alerts' as const; | ||
} | ||
|
||
if (decision === AlertState.NOT_SUSPICIOUS) { | ||
return 'not_suspicious_alerts' as const; | ||
} | ||
|
||
if (decision === AlertState.TRIGGERED) { | ||
return 'revert_decision_alerts' as const; | ||
} | ||
|
||
throw new Error(`Invalid decision: "${decision}"`); | ||
}; | ||
|
||
export const useAlertsDecisionByIdsMutation = ({ | ||
onSuccess, | ||
}: { | ||
onSuccess?: <TData>(data: TData, { decision }: { decision: TAlertState }) => void; | ||
} = {}) => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: ({ decision, alertIds }: { decision: TAlertState; alertIds: string[] }) => | ||
updateAlertsDecisionByIds({ | ||
decision, | ||
alertIds, | ||
}), | ||
onSuccess: (data, { decision }) => { | ||
void queryClient.invalidateQueries(); | ||
|
||
const action = getToastAction(decision); | ||
|
||
toast.success(t(`toast:${action}.success`)); | ||
onSuccess?.(data, { decision }); | ||
}, | ||
onError: (error, { decision }) => { | ||
const action = getToastAction(decision); | ||
|
||
toast.error(t(`toast:${action}.error`)); | ||
}, | ||
}); | ||
}; |
This file contains 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 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 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
Oops, something went wrong.