Files
ncd-fe/packages/pl-fe/src/actions/reports.ts
nicole mikołajczyk 0c5b15ec7b nicolium: use @ imports when they save a char
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
2026-02-27 00:30:24 +01:00

49 lines
1.2 KiB
TypeScript

import { getClient } from '@/api';
import { useModalsStore } from '@/stores/modals';
import type { NormalizedStatus as Status } from '@/reducers/statuses';
import type { AppDispatch, RootState } from '@/store';
import type { Account } from 'pl-api';
enum ReportableEntities {
ACCOUNT = 'ACCOUNT',
STATUS = 'STATUS',
}
type ReportedEntity = {
status?: Pick<Status, 'id'>;
statusId?: string;
};
const initReport = (
entityType: ReportableEntities,
account: Pick<Account, 'id'>,
entities?: ReportedEntity,
) => {
const { status, statusId } = entities ?? {};
useModalsStore.getState().actions.openModal('REPORT', {
accountId: account.id,
entityType,
statusIds: [status?.id, statusId].filter((id): id is string => !!id),
});
};
const submitReport =
(
accountId: string,
statusIds: string[],
ruleIds?: string[],
comment?: string,
forward?: boolean,
) =>
(dispatch: AppDispatch, getState: () => RootState) =>
getClient(getState()).accounts.reportAccount(accountId, {
status_ids: statusIds,
rule_ids: ruleIds,
comment: comment,
forward: forward,
});
export { ReportableEntities, initReport, submitReport };