Skip to content

Commit

Permalink
refactor(backoffice-v2): addressed PR comments for toasts string lite…
Browse files Browse the repository at this point in the history
…rals
  • Loading branch information
Omri-Levy committed Feb 18, 2024
1 parent 2abd651 commit 9144466
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
10 changes: 10 additions & 0 deletions apps/backoffice-v2/src/common/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ComponentProps, FunctionComponent, PropsWithChildren } from 'react';
import { Action, Method, Resource, State } from './enums';
import translations from '../../public/locales/en/toast.json';

export type WithRequired<TObject, TKey extends keyof TObject> = TObject & {
[TProperty in TKey]-?: TObject[TProperty];
Expand Down Expand Up @@ -47,3 +48,12 @@ export type TypesafeOmit<TObj extends Record<PropertyKey, unknown>, TProps exten
export type UnknownRecord = Record<PropertyKey, unknown>;

export type NoInfer<T> = [T][T extends any ? 0 : never];

export type TToastKeyWithSuccessAndError = {
[TKey in keyof typeof translations]: (typeof translations)[TKey] extends {
success: string;
error: string;
}
? TKey
: never;
}[keyof typeof translations];
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ 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) => {
const getToastAction = (decision: TAlertState): TToastKeyWithSuccessAndError => {
if (decision === AlertState.REJECTED) {
return 'reject_alerts' as const;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useUsersQuery } from '@/domains/users/hooks/queries/useUsersQuery/useUs
import toast from 'react-hot-toast';
import { t } from 'i18next';
import { assignAlertsByIds } from '@/domains/alerts/fetchers';
import { TToastKeyWithSuccessAndError } from '@/common/types';

const getToastActionAndContext = ({
assigneeId,
Expand All @@ -12,7 +13,10 @@ const getToastActionAndContext = ({
assigneeId: string | null;
assigneeName: string | null;
isAssignedToMe: boolean;
}) => {
}): {
action: TToastKeyWithSuccessAndError;
context: Record<string, string>;
} => {
const action = assigneeId ? 'assign_alerts' : 'unassign_alerts';
const context = assigneeId
? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import toast from 'react-hot-toast';
import { t } from 'i18next';
import { updateWorkflowSetAssignById } from '../../../fetchers';
import { useUsersQuery } from '../../../../users/hooks/queries/useUsersQuery/useUsersQuery';
import { TToastKeyWithSuccessAndError } from '@/common/types';

const getToastActionAndContext = ({
assigneeId,
Expand All @@ -12,7 +13,10 @@ const getToastActionAndContext = ({
assigneeId: string | null;
assigneeName: string | null;
isAssignedToMe: boolean;
}) => {
}): {
action: TToastKeyWithSuccessAndError;
context: Record<string, string>;
} => {
const action = assigneeId ? 'assign_case' : 'unassign_case';
const context = assigneeId
? {
Expand Down

0 comments on commit 9144466

Please sign in to comment.