pl-fe: remove remaining AnyAction from reducers
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
5b07c47f68
commit
627a810503
5 changed files with 91 additions and 61 deletions
|
@ -6,7 +6,7 @@ import { getClient } from '../api';
|
||||||
|
|
||||||
import { deleteFromTimelines } from './timelines';
|
import { deleteFromTimelines } from './timelines';
|
||||||
|
|
||||||
import type { Account, AdminGetAccountsParams, AdminGetReportsParams, PleromaConfig, Status } from 'pl-api';
|
import type { Account, AdminAccount, AdminGetAccountsParams, AdminGetReportsParams, AdminReport, PaginatedResponse, PleromaConfig, Status } from 'pl-api';
|
||||||
import type { AppDispatch, RootState } from 'pl-fe/store';
|
import type { AppDispatch, RootState } from 'pl-fe/store';
|
||||||
|
|
||||||
const ADMIN_CONFIG_FETCH_REQUEST = 'ADMIN_CONFIG_FETCH_REQUEST' as const;
|
const ADMIN_CONFIG_FETCH_REQUEST = 'ADMIN_CONFIG_FETCH_REQUEST' as const;
|
||||||
|
@ -106,16 +106,16 @@ const fetchReports = (params?: AdminGetReportsParams) =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
|
||||||
dispatch({ type: ADMIN_REPORTS_FETCH_REQUEST, params });
|
dispatch<AdminActions>({ type: ADMIN_REPORTS_FETCH_REQUEST, params });
|
||||||
|
|
||||||
return getClient(state).admin.reports.getReports(params)
|
return getClient(state).admin.reports.getReports(params)
|
||||||
.then(({ items }) => {
|
.then(({ items }) => {
|
||||||
items.forEach((report) => {
|
items.forEach((report) => {
|
||||||
dispatch(importEntities({ statuses: report.statuses as Array<Status>, accounts: [report.account?.account, report.target_account?.account] }));
|
dispatch(importEntities({ statuses: report.statuses as Array<Status>, accounts: [report.account?.account, report.target_account?.account] }));
|
||||||
dispatch({ type: ADMIN_REPORTS_FETCH_SUCCESS, reports: items, params });
|
dispatch<AdminActions>({ type: ADMIN_REPORTS_FETCH_SUCCESS, reports: items, params });
|
||||||
});
|
});
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch({ type: ADMIN_REPORTS_FETCH_FAIL, error, params });
|
dispatch<AdminActions>({ type: ADMIN_REPORTS_FETCH_FAIL, error, params });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -123,12 +123,12 @@ const closeReport = (reportId: string) =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
|
||||||
dispatch({ type: ADMIN_REPORT_PATCH_REQUEST, reportId });
|
dispatch<AdminActions>({ type: ADMIN_REPORT_PATCH_REQUEST, reportId });
|
||||||
|
|
||||||
return getClient(state).admin.reports.resolveReport(reportId).then((report) => {
|
return getClient(state).admin.reports.resolveReport(reportId).then((report) => {
|
||||||
dispatch({ type: ADMIN_REPORT_PATCH_SUCCESS, report, reportId });
|
dispatch<AdminActions>({ type: ADMIN_REPORT_PATCH_SUCCESS, report, reportId });
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch({ type: ADMIN_REPORT_PATCH_FAIL, error, reportId });
|
dispatch<AdminActions>({ type: ADMIN_REPORT_PATCH_FAIL, error, reportId });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -136,15 +136,15 @@ const fetchUsers = (params?: AdminGetAccountsParams) =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
|
||||||
dispatch({ type: ADMIN_USERS_FETCH_REQUEST, params });
|
dispatch<AdminActions>({ type: ADMIN_USERS_FETCH_REQUEST, params });
|
||||||
|
|
||||||
return getClient(state).admin.accounts.getAccounts(params).then((res) => {
|
return getClient(state).admin.accounts.getAccounts(params).then((res) => {
|
||||||
dispatch(importEntities({ accounts: res.items.map(({ account }) => account).filter((account): account is Account => account !== null) }));
|
dispatch(importEntities({ accounts: res.items.map(({ account }) => account).filter((account): account is Account => account !== null) }));
|
||||||
dispatch(fetchRelationships(res.items.map((account) => account.id)));
|
dispatch(fetchRelationships(res.items.map((account) => account.id)));
|
||||||
dispatch({ type: ADMIN_USERS_FETCH_SUCCESS, users: res.items, params, next: res.next });
|
dispatch<AdminActions>({ type: ADMIN_USERS_FETCH_SUCCESS, users: res.items, params, next: res.next });
|
||||||
return res;
|
return res;
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch({ type: ADMIN_USERS_FETCH_FAIL, error, params });
|
dispatch<AdminActions>({ type: ADMIN_USERS_FETCH_FAIL, error, params });
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -153,20 +153,20 @@ const deactivateUser = (accountId: string, report_id?: string) =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
|
||||||
dispatch({ type: ADMIN_USER_DEACTIVATE_REQUEST, accountId });
|
dispatch<AdminActions>({ type: ADMIN_USER_DEACTIVATE_REQUEST, accountId });
|
||||||
|
|
||||||
return getClient(state).admin.accounts.performAccountAction(accountId, 'suspend', { report_id });
|
return getClient(state).admin.accounts.performAccountAction(accountId, 'suspend', { report_id });
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteUser = (accountId: string) =>
|
const deleteUser = (accountId: string) =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
dispatch({ type: ADMIN_USER_DELETE_REQUEST, accountId });
|
dispatch<AdminActions>({ type: ADMIN_USER_DELETE_REQUEST, accountId });
|
||||||
|
|
||||||
return getClient(getState).admin.accounts.deleteAccount(accountId)
|
return getClient(getState).admin.accounts.deleteAccount(accountId)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
dispatch({ type: ADMIN_USER_DELETE_SUCCESS, accountId });
|
dispatch<AdminActions>({ type: ADMIN_USER_DELETE_SUCCESS, accountId });
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch({ type: ADMIN_USER_DELETE_FAIL, error, accountId });
|
dispatch<AdminActions>({ type: ADMIN_USER_DELETE_FAIL, error, accountId });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -174,57 +174,57 @@ const approveUser = (accountId: string) =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
|
||||||
dispatch({ type: ADMIN_USER_APPROVE_REQUEST, accountId });
|
dispatch<AdminActions>({ type: ADMIN_USER_APPROVE_REQUEST, accountId });
|
||||||
|
|
||||||
return getClient(state).admin.accounts.approveAccount(accountId)
|
return getClient(state).admin.accounts.approveAccount(accountId)
|
||||||
.then((user) => {
|
.then((user) => {
|
||||||
dispatch({ type: ADMIN_USER_APPROVE_SUCCESS, user, accountId });
|
dispatch<AdminActions>({ type: ADMIN_USER_APPROVE_SUCCESS, user, accountId });
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch({ type: ADMIN_USER_APPROVE_FAIL, error, accountId });
|
dispatch<AdminActions>({ type: ADMIN_USER_APPROVE_FAIL, error, accountId });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteStatus = (statusId: string) =>
|
const deleteStatus = (statusId: string) =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
dispatch({ type: ADMIN_STATUS_DELETE_REQUEST, statusId });
|
dispatch<AdminActions>({ type: ADMIN_STATUS_DELETE_REQUEST, statusId });
|
||||||
return getClient(getState).admin.statuses.deleteStatus(statusId)
|
return getClient(getState).admin.statuses.deleteStatus(statusId)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
dispatch(deleteFromTimelines(statusId));
|
dispatch(deleteFromTimelines(statusId));
|
||||||
return dispatch({ type: ADMIN_STATUS_DELETE_SUCCESS, statusId });
|
return dispatch<AdminActions>({ type: ADMIN_STATUS_DELETE_SUCCESS, statusId });
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
return dispatch({ type: ADMIN_STATUS_DELETE_FAIL, error, statusId });
|
return dispatch<AdminActions>({ type: ADMIN_STATUS_DELETE_FAIL, error, statusId });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleStatusSensitivity = (statusId: string, sensitive: boolean) =>
|
const toggleStatusSensitivity = (statusId: string, sensitive: boolean) =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
dispatch({ type: ADMIN_STATUS_TOGGLE_SENSITIVITY_REQUEST, statusId });
|
dispatch<AdminActions>({ type: ADMIN_STATUS_TOGGLE_SENSITIVITY_REQUEST, statusId });
|
||||||
return getClient(getState).admin.statuses.updateStatus(statusId, { sensitive: !sensitive })
|
return getClient(getState).admin.statuses.updateStatus(statusId, { sensitive: !sensitive })
|
||||||
.then((status) => {
|
.then((status) => {
|
||||||
dispatch(importEntities({ statuses: [status] }));
|
dispatch(importEntities({ statuses: [status] }));
|
||||||
dispatch({ type: ADMIN_STATUS_TOGGLE_SENSITIVITY_SUCCESS, statusId, status });
|
dispatch<AdminActions>({ type: ADMIN_STATUS_TOGGLE_SENSITIVITY_SUCCESS, statusId, status });
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch({ type: ADMIN_STATUS_TOGGLE_SENSITIVITY_FAIL, error, statusId });
|
dispatch<AdminActions>({ type: ADMIN_STATUS_TOGGLE_SENSITIVITY_FAIL, error, statusId });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const tagUser = (accountId: string, tags: string[]) =>
|
const tagUser = (accountId: string, tags: string[]) =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
dispatch({ type: ADMIN_USER_TAG_REQUEST, accountId, tags });
|
dispatch<AdminActions>({ type: ADMIN_USER_TAG_REQUEST, accountId, tags });
|
||||||
return getClient(getState).admin.accounts.tagUser(accountId, tags).then(() => {
|
return getClient(getState).admin.accounts.tagUser(accountId, tags).then(() => {
|
||||||
dispatch({ type: ADMIN_USER_TAG_SUCCESS, accountId, tags });
|
dispatch<AdminActions>({ type: ADMIN_USER_TAG_SUCCESS, accountId, tags });
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch({ type: ADMIN_USER_TAG_FAIL, error, accountId, tags });
|
dispatch<AdminActions>({ type: ADMIN_USER_TAG_FAIL, error, accountId, tags });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const untagUser = (accountId: string, tags: string[]) =>
|
const untagUser = (accountId: string, tags: string[]) =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
dispatch({ type: ADMIN_USER_UNTAG_REQUEST, accountId, tags });
|
dispatch<AdminActions>({ type: ADMIN_USER_UNTAG_REQUEST, accountId, tags });
|
||||||
return getClient(getState).admin.accounts.untagUser(accountId, tags).then(() => {
|
return getClient(getState).admin.accounts.untagUser(accountId, tags).then(() => {
|
||||||
dispatch({ type: ADMIN_USER_UNTAG_SUCCESS, accountId, tags });
|
dispatch<AdminActions>({ type: ADMIN_USER_UNTAG_SUCCESS, accountId, tags });
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch({ type: ADMIN_USER_UNTAG_FAIL, error, accountId, tags });
|
dispatch<AdminActions>({ type: ADMIN_USER_UNTAG_FAIL, error, accountId, tags });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -278,7 +278,7 @@ const fetchUserIndex = () =>
|
||||||
|
|
||||||
if (isLoading) return;
|
if (isLoading) return;
|
||||||
|
|
||||||
dispatch({ type: ADMIN_USER_INDEX_FETCH_REQUEST });
|
dispatch<AdminActions>({ type: ADMIN_USER_INDEX_FETCH_REQUEST });
|
||||||
|
|
||||||
const params: AdminGetAccountsParams = {
|
const params: AdminGetAccountsParams = {
|
||||||
origin: 'local',
|
origin: 'local',
|
||||||
|
@ -289,9 +289,9 @@ const fetchUserIndex = () =>
|
||||||
dispatch(fetchUsers(params))
|
dispatch(fetchUsers(params))
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
const { items, total, next } = data;
|
const { items, total, next } = data;
|
||||||
dispatch({ type: ADMIN_USER_INDEX_FETCH_SUCCESS, users: items, total, next, params });
|
dispatch<AdminActions>({ type: ADMIN_USER_INDEX_FETCH_SUCCESS, users: items, total, next, params });
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
dispatch({ type: ADMIN_USER_INDEX_FETCH_FAIL });
|
dispatch<AdminActions>({ type: ADMIN_USER_INDEX_FETCH_FAIL });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -301,14 +301,14 @@ const expandUserIndex = () =>
|
||||||
|
|
||||||
if (!loaded || isLoading || !next) return;
|
if (!loaded || isLoading || !next) return;
|
||||||
|
|
||||||
dispatch({ type: ADMIN_USER_INDEX_EXPAND_REQUEST });
|
dispatch<AdminActions>({ type: ADMIN_USER_INDEX_EXPAND_REQUEST });
|
||||||
|
|
||||||
next()
|
next()
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
const { items, total, next } = data;
|
const { items, total, next } = data;
|
||||||
dispatch({ type: ADMIN_USER_INDEX_EXPAND_SUCCESS, users: items, total, next, params });
|
dispatch<AdminActions>({ type: ADMIN_USER_INDEX_EXPAND_SUCCESS, users: items, total, next, params });
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
dispatch({ type: ADMIN_USER_INDEX_EXPAND_FAIL });
|
dispatch<AdminActions>({ type: ADMIN_USER_INDEX_EXPAND_FAIL });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -319,6 +319,41 @@ type AdminActions =
|
||||||
| { type: typeof ADMIN_CONFIG_UPDATE_REQUEST; configs: PleromaConfig['configs'] }
|
| { type: typeof ADMIN_CONFIG_UPDATE_REQUEST; configs: PleromaConfig['configs'] }
|
||||||
| { type: typeof ADMIN_CONFIG_UPDATE_SUCCESS; configs: PleromaConfig['configs']; needsReboot: boolean }
|
| { type: typeof ADMIN_CONFIG_UPDATE_SUCCESS; configs: PleromaConfig['configs']; needsReboot: boolean }
|
||||||
| { type: typeof ADMIN_CONFIG_UPDATE_FAIL; error: unknown; configs: PleromaConfig['configs'] }
|
| { type: typeof ADMIN_CONFIG_UPDATE_FAIL; error: unknown; configs: PleromaConfig['configs'] }
|
||||||
|
| { type: typeof ADMIN_REPORTS_FETCH_REQUEST; params?: AdminGetReportsParams }
|
||||||
|
| { type: typeof ADMIN_REPORTS_FETCH_SUCCESS; reports: Array<AdminReport>; params?: AdminGetReportsParams }
|
||||||
|
| { type: typeof ADMIN_REPORTS_FETCH_FAIL; error: unknown; params?: AdminGetReportsParams }
|
||||||
|
| { type: typeof ADMIN_REPORT_PATCH_REQUEST; reportId: string }
|
||||||
|
| { type: typeof ADMIN_REPORT_PATCH_SUCCESS; report: AdminReport; reportId: string }
|
||||||
|
| { type: typeof ADMIN_REPORT_PATCH_FAIL; error: unknown; reportId: string }
|
||||||
|
| { type: typeof ADMIN_USERS_FETCH_REQUEST; params?: AdminGetAccountsParams }
|
||||||
|
| { type: typeof ADMIN_USERS_FETCH_SUCCESS; users: Array<AdminAccount>; params?: AdminGetAccountsParams; next: (() => Promise<PaginatedResponse<AdminAccount>>) | null }
|
||||||
|
| { type: typeof ADMIN_USERS_FETCH_FAIL; error: unknown; params?: AdminGetAccountsParams }
|
||||||
|
| { type: typeof ADMIN_USER_DEACTIVATE_REQUEST; accountId: string }
|
||||||
|
| { type: typeof ADMIN_USER_DELETE_REQUEST; accountId: string }
|
||||||
|
| { type: typeof ADMIN_USER_DELETE_SUCCESS; accountId: string }
|
||||||
|
| { type: typeof ADMIN_USER_DELETE_FAIL; error: unknown; accountId: string }
|
||||||
|
| { type: typeof ADMIN_USER_APPROVE_REQUEST; accountId: string }
|
||||||
|
| { type: typeof ADMIN_USER_APPROVE_SUCCESS; user: AdminAccount; accountId: string }
|
||||||
|
| { type: typeof ADMIN_USER_APPROVE_FAIL; error: unknown; accountId: string }
|
||||||
|
| { type: typeof ADMIN_STATUS_DELETE_REQUEST; statusId: string }
|
||||||
|
| { type: typeof ADMIN_STATUS_DELETE_SUCCESS; statusId: string }
|
||||||
|
| { type: typeof ADMIN_STATUS_DELETE_FAIL; error: unknown; statusId: string }
|
||||||
|
| { type: typeof ADMIN_STATUS_TOGGLE_SENSITIVITY_REQUEST; statusId: string }
|
||||||
|
| { type: typeof ADMIN_STATUS_TOGGLE_SENSITIVITY_SUCCESS; statusId: string; status: Status }
|
||||||
|
| { type: typeof ADMIN_STATUS_TOGGLE_SENSITIVITY_FAIL; error: unknown; statusId: string }
|
||||||
|
| { type: typeof ADMIN_USER_TAG_REQUEST; accountId: string; tags: Array<string> }
|
||||||
|
| { type: typeof ADMIN_USER_TAG_SUCCESS; accountId: string; tags: Array<string> }
|
||||||
|
| { type: typeof ADMIN_USER_TAG_FAIL; error: unknown; accountId: string; tags: Array<string> }
|
||||||
|
| { type: typeof ADMIN_USER_UNTAG_REQUEST; accountId: string; tags: Array<string> }
|
||||||
|
| { type: typeof ADMIN_USER_UNTAG_SUCCESS; accountId: string; tags: Array<string> }
|
||||||
|
| { type: typeof ADMIN_USER_UNTAG_FAIL; error: unknown; accountId: string; tags: Array<string> }
|
||||||
|
| ReturnType<typeof setUserIndexQuery>
|
||||||
|
| { type: typeof ADMIN_USER_INDEX_FETCH_REQUEST }
|
||||||
|
| { type: typeof ADMIN_USER_INDEX_FETCH_SUCCESS; users: Array<AdminAccount>; total?: number; next: (() => Promise<PaginatedResponse<AdminAccount>>) | null; params?: AdminGetAccountsParams }
|
||||||
|
| { type: typeof ADMIN_USER_INDEX_FETCH_FAIL }
|
||||||
|
| { type: typeof ADMIN_USER_INDEX_EXPAND_REQUEST }
|
||||||
|
| { type: typeof ADMIN_USER_INDEX_EXPAND_SUCCESS; users: Array<AdminAccount>; total?: number; next: (() => Promise<PaginatedResponse<AdminAccount>>) | null; params: AdminGetAccountsParams | null }
|
||||||
|
| { type: typeof ADMIN_USER_INDEX_EXPAND_FAIL };
|
||||||
|
|
||||||
export {
|
export {
|
||||||
ADMIN_CONFIG_FETCH_REQUEST,
|
ADMIN_CONFIG_FETCH_REQUEST,
|
||||||
|
|
|
@ -39,7 +39,7 @@ const UserIndex: React.FC = () => {
|
||||||
updateQuery();
|
updateQuery();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const hasMore = items.length < total && !!next;
|
const hasMore = (total === undefined || items.length < total) && !!next;
|
||||||
|
|
||||||
const showLoading = isLoading && !items.length;
|
const showLoading = isLoading && !items.length;
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import type { AdminReport as BaseAdminReport } from 'pl-api';
|
import type { AdminReport as BaseAdminReport } from 'pl-api';
|
||||||
|
|
||||||
const normalizeAdminReport = (report: BaseAdminReport) => ({
|
const normalizeAdminReport = ({
|
||||||
|
account, target_account, action_taken_by_account, assigned_account, statuses, ...report
|
||||||
|
}: BaseAdminReport) => ({
|
||||||
...report,
|
...report,
|
||||||
account_id: report.account?.id || null,
|
account_id: account?.id || null,
|
||||||
target_account_id: report.target_account?.id || null,
|
target_account_id: target_account?.id || null,
|
||||||
action_taken_by_account_id: report.action_taken_by_account?.id || null,
|
action_taken_by_account_id: action_taken_by_account?.id || null,
|
||||||
assigned_account_id: report.assigned_account?.id || null,
|
assigned_account_id: assigned_account?.id || null,
|
||||||
status_ids: report.statuses.map(status => status.id),
|
status_ids: statuses.map(status => status.id),
|
||||||
});
|
});
|
||||||
|
|
||||||
type AdminReport = ReturnType<typeof normalizeAdminReport>;
|
type AdminReport = ReturnType<typeof normalizeAdminReport>;
|
||||||
|
|
|
@ -8,9 +8,9 @@ import {
|
||||||
ADMIN_USER_INDEX_FETCH_REQUEST,
|
ADMIN_USER_INDEX_FETCH_REQUEST,
|
||||||
ADMIN_USER_INDEX_FETCH_SUCCESS,
|
ADMIN_USER_INDEX_FETCH_SUCCESS,
|
||||||
ADMIN_USER_INDEX_QUERY_SET,
|
ADMIN_USER_INDEX_QUERY_SET,
|
||||||
|
type AdminActions,
|
||||||
} from 'pl-fe/actions/admin';
|
} from 'pl-fe/actions/admin';
|
||||||
|
|
||||||
import type { AnyAction } from '@reduxjs/toolkit';
|
|
||||||
import type { AdminAccount, AdminGetAccountsParams, PaginatedResponse } from 'pl-api';
|
import type { AdminAccount, AdminGetAccountsParams, PaginatedResponse } from 'pl-api';
|
||||||
import type { APIEntity } from 'pl-fe/types/entities';
|
import type { APIEntity } from 'pl-fe/types/entities';
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ type State = {
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
loaded: boolean;
|
loaded: boolean;
|
||||||
items: Array<string>;
|
items: Array<string>;
|
||||||
total: number;
|
total?: number;
|
||||||
page: number;
|
page: number;
|
||||||
query: string;
|
query: string;
|
||||||
next: (() => Promise<PaginatedResponse<AdminAccount>>) | null;
|
next: (() => Promise<PaginatedResponse<AdminAccount>>) | null;
|
||||||
|
@ -36,7 +36,7 @@ const initialState: State = {
|
||||||
params: null,
|
params: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const admin_user_index = (state: State = initialState, action: AnyAction): State => {
|
const admin_user_index = (state: State = initialState, action: AdminActions): State => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ADMIN_USER_INDEX_QUERY_SET:
|
case ADMIN_USER_INDEX_QUERY_SET:
|
||||||
return create(state, draft => {
|
return create(state, draft => {
|
||||||
|
@ -47,7 +47,7 @@ const admin_user_index = (state: State = initialState, action: AnyAction): State
|
||||||
draft.isLoading = true;
|
draft.isLoading = true;
|
||||||
draft.loaded = true;
|
draft.loaded = true;
|
||||||
draft.items = [];
|
draft.items = [];
|
||||||
draft.total = action.total;
|
draft.total = Infinity;
|
||||||
draft.page = 0;
|
draft.page = 0;
|
||||||
draft.next = null;
|
draft.next = null;
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,12 +10,12 @@ import {
|
||||||
ADMIN_USER_DELETE_SUCCESS,
|
ADMIN_USER_DELETE_SUCCESS,
|
||||||
ADMIN_USER_APPROVE_REQUEST,
|
ADMIN_USER_APPROVE_REQUEST,
|
||||||
ADMIN_USER_APPROVE_SUCCESS,
|
ADMIN_USER_APPROVE_SUCCESS,
|
||||||
|
type AdminActions,
|
||||||
} from 'pl-fe/actions/admin';
|
} from 'pl-fe/actions/admin';
|
||||||
import { normalizeAdminReport, type AdminReport } from 'pl-fe/normalizers/admin-report';
|
import { normalizeAdminReport, type AdminReport as MinifiedReport } from 'pl-fe/normalizers/admin-report';
|
||||||
|
|
||||||
import type { AdminAccount, AdminGetAccountsParams, AdminReport as BaseAdminReport } from 'pl-api';
|
import type { AdminAccount, AdminGetAccountsParams, AdminReport } from 'pl-api';
|
||||||
import type { Config } from 'pl-fe/utils/config-db';
|
import type { Config } from 'pl-fe/utils/config-db';
|
||||||
import type { AnyAction } from 'redux';
|
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
reports: Record<string, MinifiedReport>;
|
reports: Record<string, MinifiedReport>;
|
||||||
|
@ -59,7 +59,7 @@ const minifyUser = (user: AdminAccount) => omit(user, ['account']);
|
||||||
|
|
||||||
type MinifiedUser = ReturnType<typeof minifyUser>;
|
type MinifiedUser = ReturnType<typeof minifyUser>;
|
||||||
|
|
||||||
const importUsers = (state: State, users: Array<AdminAccount>, params: AdminGetAccountsParams) => {
|
const importUsers = (state: State, users: Array<AdminAccount>, params?: AdminGetAccountsParams) => {
|
||||||
maybeImportUnapproved(state, users, params);
|
maybeImportUnapproved(state, users, params);
|
||||||
maybeImportLatest(state, users, params);
|
maybeImportLatest(state, users, params);
|
||||||
|
|
||||||
|
@ -80,16 +80,9 @@ const approveUser = (state: State, user: AdminAccount) => {
|
||||||
state.users[user.id] = normalizedUser;
|
state.users[user.id] = normalizedUser;
|
||||||
};
|
};
|
||||||
|
|
||||||
const minifyReport = (report: AdminReport) => omit(
|
const importReports = (state: State, reports: Array<AdminReport>) => {
|
||||||
report,
|
|
||||||
['account', 'target_account', 'action_taken_by_account', 'assigned_account', 'statuses'],
|
|
||||||
);
|
|
||||||
|
|
||||||
type MinifiedReport = ReturnType<typeof minifyReport>;
|
|
||||||
|
|
||||||
const importReports = (state: State, reports: Array<BaseAdminReport>) => {
|
|
||||||
reports.forEach(report => {
|
reports.forEach(report => {
|
||||||
const minifiedReport = minifyReport(normalizeAdminReport(report));
|
const minifiedReport = normalizeAdminReport(report);
|
||||||
if (!minifiedReport.action_taken) {
|
if (!minifiedReport.action_taken) {
|
||||||
state.openReports = [...new Set([...state.openReports, report.id])];
|
state.openReports = [...new Set([...state.openReports, report.id])];
|
||||||
}
|
}
|
||||||
|
@ -97,7 +90,7 @@ const importReports = (state: State, reports: Array<BaseAdminReport>) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleReportDiffs = (state: State, report: MinifiedReport) => {
|
const handleReportDiffs = (state: State, report: AdminReport) => {
|
||||||
// Note: the reports here aren't full report objects
|
// Note: the reports here aren't full report objects
|
||||||
// hence the need for a new function.
|
// hence the need for a new function.
|
||||||
switch (report.action_taken) {
|
switch (report.action_taken) {
|
||||||
|
@ -113,7 +106,7 @@ const importConfigs = (state: State, configs: any) => {
|
||||||
state.configs = configs;
|
state.configs = configs;
|
||||||
};
|
};
|
||||||
|
|
||||||
const admin = (state = initialState, action: AnyAction): State => {
|
const admin = (state = initialState, action: AdminActions): State => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ADMIN_CONFIG_FETCH_SUCCESS:
|
case ADMIN_CONFIG_FETCH_SUCCESS:
|
||||||
case ADMIN_CONFIG_UPDATE_SUCCESS:
|
case ADMIN_CONFIG_UPDATE_SUCCESS:
|
||||||
|
|
Loading…
Reference in a new issue