fixed so deletion of entity also includes members
Signed-off-by: Lykke Axlin <lykkeaxlin@hotmail.com> Co-authored-by: klaraab <klarabroman@live.se>
This commit is contained in:
@@ -42,8 +42,6 @@ export interface BazaarApi {
|
||||
|
||||
deleteMember(entity: Entity): Promise<void>;
|
||||
|
||||
deleteMembers(entity: Entity): Promise<void>;
|
||||
|
||||
addMember(entity: Entity): Promise<void>;
|
||||
|
||||
getEntities(): Promise<any>;
|
||||
@@ -136,17 +134,6 @@ export class BazaarClient implements BazaarApi {
|
||||
});
|
||||
}
|
||||
|
||||
async deleteMembers(entity: Entity): Promise<void> {
|
||||
const baseUrl = await this.discoveryApi.getBaseUrl('bazaar');
|
||||
|
||||
await fetch(`${baseUrl}/members`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
entity_ref: stringifyEntityRef(entity),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getEntities(): Promise<any> {
|
||||
const baseUrl = await this.discoveryApi.getBaseUrl('bazaar');
|
||||
|
||||
@@ -157,11 +144,12 @@ export class BazaarClient implements BazaarApi {
|
||||
|
||||
async deleteEntity(bazaarProject: BazaarProject): Promise<void> {
|
||||
const baseUrl = await this.discoveryApi.getBaseUrl('bazaar');
|
||||
const entityRef = bazaarProject.entityRef as string;
|
||||
|
||||
await fetch(`${baseUrl}/metadata`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
entity_ref: bazaarProject.entityRef as string,
|
||||
entity_ref: entityRef,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -169,8 +157,7 @@ export class BazaarClient implements BazaarApi {
|
||||
await fetch(`${baseUrl}/members`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
user_id: this.identityApi.getUserId(),
|
||||
entity_ref: bazaarProject.entityRef as string,
|
||||
entity_ref: entityRef,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ export const EntityBazaarInfoCard = () => {
|
||||
const [isBazaar, setIsBazaar] = useState(false);
|
||||
const [members, fetchMembers] = useAsyncFn(async () => {
|
||||
const response = await bazaarApi.getMembers(entity);
|
||||
|
||||
const dbMembers = response.data.map((obj: any) => {
|
||||
const member: Member = {
|
||||
userId: obj.user_id,
|
||||
@@ -110,15 +111,17 @@ export const EntityBazaarInfoCard = () => {
|
||||
if (response) {
|
||||
const metadata = await response.json().then((resp: any) => resp.data[0]);
|
||||
|
||||
return {
|
||||
entityRef: metadata.entity_ref,
|
||||
name: metadata.name,
|
||||
community: metadata.community,
|
||||
announcement: metadata.announcement,
|
||||
status: metadata.status,
|
||||
updatedAt: metadata.updated_at,
|
||||
membersCount: metadata.members_count,
|
||||
} as BazaarProject;
|
||||
if (metadata) {
|
||||
return {
|
||||
entityRef: metadata.entity_ref,
|
||||
name: metadata.name,
|
||||
community: metadata.community,
|
||||
announcement: metadata.announcement,
|
||||
status: metadata.status,
|
||||
updatedAt: metadata.updated_at,
|
||||
membersCount: metadata.members_count,
|
||||
} as BazaarProject;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
@@ -133,7 +136,7 @@ export const EntityBazaarInfoCard = () => {
|
||||
members?.value
|
||||
?.map((member: Member) => member.userId)
|
||||
.indexOf(identity.getUserId()) >= 0;
|
||||
const isBazaarProject = bazaarProject !== null;
|
||||
const isBazaarProject = bazaarProject.value !== null;
|
||||
|
||||
setIsMember(isBazaarMember);
|
||||
setIsBazaar(isBazaarProject);
|
||||
@@ -164,15 +167,10 @@ export const EntityBazaarInfoCard = () => {
|
||||
}
|
||||
|
||||
fetchMembers();
|
||||
fetchBazaarProject();
|
||||
};
|
||||
|
||||
const links: IconLinkVerticalProps[] = [
|
||||
{
|
||||
label: 'Community',
|
||||
icon: <ChatIcon />,
|
||||
href: bazaarProject?.value?.community,
|
||||
disabled: bazaarProject?.value?.community === '',
|
||||
},
|
||||
{
|
||||
label: isMember ? 'Leave' : 'Join',
|
||||
icon: isMember ? <ExitToAppIcon /> : <PersonAddIcon />,
|
||||
@@ -181,6 +179,12 @@ export const EntityBazaarInfoCard = () => {
|
||||
handleMembersClick();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Community',
|
||||
icon: <ChatIcon />,
|
||||
href: bazaarProject?.value?.community,
|
||||
disabled: bazaarProject?.value?.community === '',
|
||||
},
|
||||
];
|
||||
|
||||
if (!isBazaar) {
|
||||
|
||||
Reference in New Issue
Block a user