-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { FormattedMessage } from '@edx/frontend-platform/i18n'; | ||
import { | ||
Button, | ||
} from '@openedx/paragon'; | ||
|
||
import messages from './messages'; | ||
|
||
const AddLibraryTeamMember = ({ | ||
onSave, | ||
onCancel, | ||
}: { | ||
onSave: () => void, | ||
onCancel: () => void, | ||
}) => { | ||
Check failure on line 14 in src/library-authoring/library-team/AddLibraryTeamMember.tsx GitHub Actions / tests (18)
|
||
return ( | ||
<div> | ||
<div>Add form goes here</div> | ||
<Button variant='tertiary' size='sm' onClick={onCancel}> | ||
Check failure on line 18 in src/library-authoring/library-team/AddLibraryTeamMember.tsx GitHub Actions / tests (18)
Check failure on line 18 in src/library-authoring/library-team/AddLibraryTeamMember.tsx GitHub Actions / tests (18)
Check failure on line 18 in src/library-authoring/library-team/AddLibraryTeamMember.tsx GitHub Actions / tests (20)
|
||
<FormattedMessage {...messages.cancel } /> | ||
Check failure on line 19 in src/library-authoring/library-team/AddLibraryTeamMember.tsx GitHub Actions / tests (18)
|
||
</Button> | ||
<Button variant='primary' size='sm' onClick={onSave}> | ||
Check failure on line 21 in src/library-authoring/library-team/AddLibraryTeamMember.tsx GitHub Actions / tests (18)
Check failure on line 21 in src/library-authoring/library-team/AddLibraryTeamMember.tsx GitHub Actions / tests (18)
Check failure on line 21 in src/library-authoring/library-team/AddLibraryTeamMember.tsx GitHub Actions / tests (20)
|
||
<FormattedMessage {...messages.saveMember} /> | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AddLibraryTeamMember; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import React from 'react'; | ||
import { FormattedMessage } from '@edx/frontend-platform/i18n'; | ||
import { Button, Container } from '@openedx/paragon'; | ||
import { Add as IconAdd } from '@openedx/paragon/icons'; | ||
|
||
import Loading from '../../generic/Loading'; | ||
import AlertError from '../../generic/alert-error'; | ||
import { useContentLibrary, useLibraryTeam } from '../data/apiHooks'; | ||
import LibraryTeamMember from './LibraryTeamMember'; | ||
import AddLibraryTeamMember from './AddLibraryTeamMember'; | ||
import { LibraryRole } from './constants'; | ||
import { LibraryTeamProvider, useLibraryTeamContext } from './context'; | ||
import messages from './messages'; | ||
|
||
const _LibraryTeam = () => { | ||
const { | ||
libraryId, | ||
isAddLibraryTeamMemberOpen, | ||
openAddLibraryTeamMember, | ||
closeAddLibraryTeamMember, | ||
} = useLibraryTeamContext(); | ||
|
||
const { | ||
data: libraryData, | ||
isLoading: isLibraryLoading, | ||
} = useContentLibrary(libraryId); | ||
|
||
const { | ||
data: libraryTeamUsers, | ||
isLoading: isTeamLoading, | ||
isError, | ||
error, | ||
} = useLibraryTeam(libraryId); | ||
|
||
if (isLibraryLoading || isTeamLoading) { | ||
return <Loading />; | ||
} | ||
|
||
const canChangeRole = libraryData ? libraryData.canEditLibrary : false; | ||
const changeRole = (email: string, role: LibraryRole) => { | ||
alert(`Change ${email}'s role to ${role}`); | ||
}; | ||
const onAddMember = (email: string, role: LibraryRole) => { | ||
alert(`Add ${email} ${role}`); | ||
closeAddLibraryTeamMember(); | ||
}; | ||
const onDeleteRole = (email: string) => { | ||
alert(`Delete ${email} role`); | ||
}; | ||
const onMakeAdmin = (email) => { | ||
changeRole(email, LibraryRole.admin); | ||
}; | ||
const onMakeAuthor = (email) => { | ||
changeRole(email, LibraryRole.author); | ||
}; | ||
const onMakeReader = (email) => { | ||
changeRole(email, LibraryRole.read); | ||
}; | ||
|
||
return ( | ||
<Container size="xl" className="library-team px-4"> | ||
{canChangeRole && ( | ||
<Button | ||
variant="primary" | ||
iconBefore={IconAdd} | ||
size="sm" | ||
onClick={openAddLibraryTeamMember} | ||
> | ||
<FormattedMessage {...messages.addNewMember} />} | ||
</Button> | ||
)} | ||
<section className="library-team-section"> | ||
{canChangeRole && isAddLibraryTeamMemberOpen && ( | ||
<AddLibraryTeamMember | ||
onSave={onAddMember} | ||
onCancel={closeAddLibraryTeamMember} | ||
/> | ||
)} | ||
<div className="members-container"> | ||
{libraryTeamUsers && libraryTeamUsers.length ? ( | ||
libraryTeamUsers.map(({ username, accessLevel: role, email }) => ( | ||
<LibraryTeamMember | ||
userName={username} | ||
role={LibraryRole[role] ?? LibraryRole.unknown} | ||
email={email} | ||
canChangeRole={canChangeRole} | ||
onMakeAdmin={canChangeRole && role !== LibraryRole.admin ? onMakeAdmin : null} | ||
onMakeAuthor={canChangeRole && role !== LibraryRole.author ? onMakeAuthor : null} | ||
onMakeReader={canChangeRole && role !== LibraryRole.read ? onMakeReader : null} | ||
onDeleteRole={canChangeRole ? onDeleteRole : null} | ||
/> | ||
)) | ||
) : <FormattedMessage {...messages.noMembersFound} />} | ||
</div> | ||
</section> | ||
{isError && (<AlertError error={error} />)} | ||
</Container> | ||
); | ||
}; | ||
|
||
const LibraryTeam = ({ libraryId }: { libraryId: string }) => ( | ||
<LibraryTeamProvider libraryId={libraryId}> | ||
<_LibraryTeam /> | ||
</LibraryTeamProvider> | ||
); | ||
|
||
export default LibraryTeam; |