Merge branch 'waitlist' into 'main'
Fix waitlist Closes #1772 See merge request soapbox-pub/soapbox!3204
This commit is contained in:
commit
efd5a54360
|
@ -149,18 +149,15 @@ function closeReports(ids: string[]) {
|
||||||
return patchReports(ids, 'closed');
|
return patchReports(ids, 'closed');
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchUsers(filters: string[] = [], page = 1, query?: string | null, pageSize = 50, url?: string | null) {
|
function fetchUsers(filters: Record<string, boolean>, page = 1, query?: string | null, pageSize = 50, url?: string | null) {
|
||||||
return async (dispatch: AppDispatch, getState: () => RootState) => {
|
return async (dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
dispatch({ type: ADMIN_USERS_FETCH_REQUEST, filters, page, pageSize });
|
dispatch({ type: ADMIN_USERS_FETCH_REQUEST, filters, page, pageSize });
|
||||||
|
|
||||||
const params: Record<string, any> = {
|
const params: Record<string, any> = {
|
||||||
|
...filters,
|
||||||
username: query,
|
username: query,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (filters.includes('local')) params.local = true;
|
|
||||||
if (filters.includes('active')) params.active = true;
|
|
||||||
if (filters.includes('need_approval')) params.pending = true;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data: accounts, ...response } = await api(getState).get(url || '/api/v1/admin/accounts', { params });
|
const { data: accounts, ...response } = await api(getState).get(url || '/api/v1/admin/accounts', { params });
|
||||||
const next = getLinks(response as AxiosResponse<any, any>).refs.find(link => link.rel === 'next')?.uri;
|
const next = getLinks(response as AxiosResponse<any, any>).refs.find(link => link.rel === 'next')?.uri;
|
||||||
|
|
|
@ -26,7 +26,7 @@ const UnapprovedAccount: React.FC<IUnapprovedAccount> = ({ accountId }) => {
|
||||||
<Account
|
<Account
|
||||||
key={adminAccount.id}
|
key={adminAccount.id}
|
||||||
account={account}
|
account={account}
|
||||||
acct={`${adminAccount.username}@${adminAccount.domain}`}
|
acct={adminAccount.domain ? `${adminAccount.username}@${adminAccount.domain}` : adminAccount.username}
|
||||||
note={adminAccount?.invite_request || ''}
|
note={adminAccount?.invite_request || ''}
|
||||||
action={(
|
action={(
|
||||||
<AuthorizeRejectButtons
|
<AuthorizeRejectButtons
|
||||||
|
|
|
@ -20,7 +20,7 @@ const AwaitingApproval: React.FC = () => {
|
||||||
const [isLoading, setLoading] = useState(true);
|
const [isLoading, setLoading] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(fetchUsers(['local', 'need_approval']))
|
dispatch(fetchUsers({ pending: true }))
|
||||||
.then(() => setLoading(false))
|
.then(() => setLoading(false))
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
|
@ -424,7 +424,7 @@ const UI: React.FC<IUI> = ({ children }) => {
|
||||||
|
|
||||||
if (account.staff) {
|
if (account.staff) {
|
||||||
dispatch(fetchReports({ resolved: false }));
|
dispatch(fetchReports({ resolved: false }));
|
||||||
dispatch(fetchUsers(['local', 'need_approval']));
|
dispatch(fetchUsers({ pending: true }));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (account.admin) {
|
if (account.admin) {
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
import {
|
import {
|
||||||
Map as ImmutableMap,
|
Map as ImmutableMap,
|
||||||
List as ImmutableList,
|
List as ImmutableList,
|
||||||
Set as ImmutableSet,
|
|
||||||
Record as ImmutableRecord,
|
Record as ImmutableRecord,
|
||||||
OrderedSet as ImmutableOrderedSet,
|
OrderedSet as ImmutableOrderedSet,
|
||||||
fromJS,
|
fromJS,
|
||||||
is,
|
|
||||||
} from 'immutable';
|
} from 'immutable';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -64,12 +62,8 @@ type SetKeys = keyof FilterConditionally<State, ImmutableOrderedSet<string>>;
|
||||||
type APIReport = { id: string; state: string; statuses: any[] };
|
type APIReport = { id: string; state: string; statuses: any[] };
|
||||||
type APIUser = { id: string; email: string; nickname: string; registration_reason: string };
|
type APIUser = { id: string; email: string; nickname: string; registration_reason: string };
|
||||||
|
|
||||||
type Filter = 'local' | 'need_approval' | 'active';
|
type Filters = Record<string, boolean>;
|
||||||
|
|
||||||
const FILTER_UNAPPROVED: Filter[] = ['local', 'need_approval'];
|
|
||||||
const FILTER_LATEST: Filter[] = ['local', 'active'];
|
|
||||||
|
|
||||||
const filtersMatch = (f1: string[], f2: string[]) => is(ImmutableSet(f1), ImmutableSet(f2));
|
|
||||||
const toIds = (items: any[]) => items.map(item => item.id);
|
const toIds = (items: any[]) => items.map(item => item.id);
|
||||||
|
|
||||||
const mergeSet = (state: State, key: SetKeys, users: APIUser[]): State => {
|
const mergeSet = (state: State, key: SetKeys, users: APIUser[]): State => {
|
||||||
|
@ -82,16 +76,16 @@ const replaceSet = (state: State, key: SetKeys, users: APIUser[]): State => {
|
||||||
return state.set(key, ImmutableOrderedSet(newIds));
|
return state.set(key, ImmutableOrderedSet(newIds));
|
||||||
};
|
};
|
||||||
|
|
||||||
const maybeImportUnapproved = (state: State, users: APIUser[], filters: Filter[]): State => {
|
const maybeImportUnapproved = (state: State, users: APIUser[], filters: Filters): State => {
|
||||||
if (filtersMatch(FILTER_UNAPPROVED, filters)) {
|
if (filters.pending) {
|
||||||
return mergeSet(state, 'awaitingApproval', users);
|
return mergeSet(state, 'awaitingApproval', users);
|
||||||
} else {
|
} else {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const maybeImportLatest = (state: State, users: APIUser[], filters: Filter[], page: number): State => {
|
const maybeImportLatest = (state: State, users: APIUser[], filters: Filters, page: number): State => {
|
||||||
if (page === 1 && filtersMatch(FILTER_LATEST, filters)) {
|
if (page === 1 && !filters.pending) {
|
||||||
return replaceSet(state, 'latestUsers', users);
|
return replaceSet(state, 'latestUsers', users);
|
||||||
} else {
|
} else {
|
||||||
return state;
|
return state;
|
||||||
|
@ -110,7 +104,7 @@ const fixUser = (user: APIEntity): ReducerAdminAccount => {
|
||||||
}) as ReducerAdminAccount;
|
}) as ReducerAdminAccount;
|
||||||
};
|
};
|
||||||
|
|
||||||
function importUsers(state: State, users: APIUser[], filters: Filter[], page: number): State {
|
function importUsers(state: State, users: APIUser[], filters: Filters, page: number): State {
|
||||||
return state.withMutations(state => {
|
return state.withMutations(state => {
|
||||||
maybeImportUnapproved(state, users, filters);
|
maybeImportUnapproved(state, users, filters);
|
||||||
maybeImportLatest(state, users, filters, page);
|
maybeImportLatest(state, users, filters, page);
|
||||||
|
@ -202,7 +196,7 @@ export default function admin(state: State = ReducerRecord(), action: AnyAction)
|
||||||
case ADMIN_REPORTS_PATCH_SUCCESS:
|
case ADMIN_REPORTS_PATCH_SUCCESS:
|
||||||
return handleReportDiffs(state, action.reports);
|
return handleReportDiffs(state, action.reports);
|
||||||
case ADMIN_USERS_FETCH_SUCCESS:
|
case ADMIN_USERS_FETCH_SUCCESS:
|
||||||
return importUsers(state, action.users, action.filters, action.page);
|
return importUsers(state, action.accounts, action.filters, action.page);
|
||||||
case ADMIN_USERS_DELETE_REQUEST:
|
case ADMIN_USERS_DELETE_REQUEST:
|
||||||
case ADMIN_USERS_DELETE_SUCCESS:
|
case ADMIN_USERS_DELETE_SUCCESS:
|
||||||
case ADMIN_USERS_REJECT_REQUEST:
|
case ADMIN_USERS_REJECT_REQUEST:
|
||||||
|
|
Loading…
Reference in New Issue