Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check all 6 collections when select set as admin for 6 #4652

Merged
merged 12 commits into from
May 21, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import React from 'react';

import { useResource } from '../../hooks/resource';
import { useAsyncState } from '../../hooks/useAsyncState';
import { userText } from '../../localization/user';
import { ajax } from '../../utils/ajax';
import { formData } from '../../utils/ajax/helpers';
import { ping } from '../../utils/ajax/ping';
import { Button } from '../Atoms/Button';
import { LoadingContext } from '../Core/Contexts';
import { fetchCollection } from '../DataModel/collection';
import type { SpecifyResource } from '../DataModel/legacyTypes';
import type { SpecifyUser } from '../DataModel/types';
import { userInformation } from '../InitialContext/userInformation';
Expand All @@ -28,7 +31,17 @@ export function AdminStatusPlugin({
const loading = React.useContext(LoadingContext);
const [user] = useResource(resource);
const isCurrentUser = userInformation.id === user.id;

const [allCollections] = useAsyncState(
React.useCallback(
async () =>
fetchCollection('Collection', { limit: 0, domainFilter: false }).then(
CarolineDenis marked this conversation as resolved.
Show resolved Hide resolved
({ records }) => records
),
[]
),
true
);
const allCollectionIds = allCollections?.map((collection) => collection.id);
return (
<Button.Small
className="w-fit"
Expand Down Expand Up @@ -60,7 +73,19 @@ export function AdminStatusPlugin({
headers: {
Accept: 'text/plain',
},
}).then(({ data }) => handleChange(data === 'true'))
})
.then(({ data }) => {
handleChange(data === 'true');
return data;
})
.then((data) => {
data === 'true'
? ping(`/context/user_collection_access_for_sp6/${user.id}/`, {
method: 'PUT',
body: allCollectionIds,
})
: undefined;
})
)
}
>
Expand Down