import type { BCMSUser } from '@becomes/cms-sdk/types'; import { BCMSJwtRoleName } from '@becomes/cms-sdk/types'; import { computed, defineComponent, type PropType } from 'vue'; import BCMSIcon from '../icon'; import { useTranslation } from '../../translations'; import { DefaultComponentProps } from '../_default'; import { BCMSOverflowMenu, BCMSOverflowMenuItem } from '../overflow'; const component = defineComponent({ props: { ...DefaultComponentProps, item: { type: Object as PropType, required: true, }, invitation: { type: Boolean, default: false, }, dashboard: { type: Boolean, default: false, }, isAdmin: Boolean, }, setup(props) { const translations = computed(() => { return useTranslation(); }); const throwable = window.bcms.util.throwable; const overflowMenuItems = computed(() => { return [ { cyTag: 'make-admin', title: translations.value.page.home.members.overflowMenu.options.admin .title, description: translations.value.page.home.members.overflowMenu.options.admin .description, icon: 'administration/users', theme: 'default', onClick() { window.open('https://cloud.thebcms.com/', '_blank'); }, }, { cyTag: 'edit-permissions', title: translations.value.page.home.members.overflowMenu.options .permissions.title, description: translations.value.page.home.members.overflowMenu.options .permissions.description, icon: 'edit', theme: 'default', onClick() { handleViewClick(); }, }, { cyTag: 'remove-user', title: translations.value.page.home.members.overflowMenu.options.remove .title, description: translations.value.page.home.members.overflowMenu.options.remove .description, icon: 'user-remove', theme: 'danger', onClick() { window.open('https://cloud.thebcms.com/', '_blank'); }, }, ]; }); function handleViewClick() { window.bcms.modal.settings.view.show({ user: props.item, async onDone(data) { await throwable( async () => { await window.bcms.sdk.user.update({ _id: props.item._id, customPool: { policy: data.policy, }, }); }, async () => { window.bcms.notification.success( translations.value.modal.viewUser.notification .userPolicySuccess, ); }, ); }, }); } return () => (
{props.invitation ? (
) : props.item.customPool.personal.avatarUri ? ( {props.item.username} ) : (
{props.item.username .split(' ') .map((word) => word[0]) .slice(0, 2) .join('')}
)}
{props.item.username} {!props.dashboard && ( {props.item.email} )}
{props.item.roles[0].name === BCMSJwtRoleName.ADMIN && ( Admin )} {props.invitation ? ( {translations.value.page.settings.team.pendingCta} ) : ( props.item.roles[0].name !== BCMSJwtRoleName.ADMIN && props.isAdmin && ( {overflowMenuItems.value.map((item, index) => { return ( ); })} ) )}
); }, }); export default component;