Skip to content

Commit

Permalink
Fix contributor title
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspergrom committed Aug 13, 2024
1 parent 377b102 commit b156392
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
<p class="flex items-center">
<span class="max-w-42 inline-block truncate">{{ jobTitle }}</span><span v-if="organization && jobTitle">&nbsp;at</span>
</p>
<lf-avatar :src="organization.logo" :name="organization.displayName" :size="18" class="!rounded border border-gray-200">
<lf-avatar
:src="organization.logo"
:name="organization.displayName"
:size="18"
class="!rounded border border-gray-200"
img-class="object-contain"
>
<template #placeholder>
<div class="w-full h-full bg-gray-50 flex items-center justify-center">
<lf-icon name="community-line" :size="14" class="text-gray-400" />
Expand Down Expand Up @@ -34,21 +40,18 @@ import { useLfSegmentsStore } from '@/modules/lf/segments/store';
import { storeToRefs } from 'pinia';
import LfAvatar from '@/ui-kit/avatar/Avatar.vue';
import LfIcon from '@/ui-kit/icon/Icon.vue';
import useContributorHelpers from '@/modules/contributor/helpers/contributor.helpers';
import { Contributor } from '@/modules/contributor/types/Contributor';
const props = defineProps<{
contributor: Contributor,
}>();
const { activeOrganization } = useContributorHelpers();
const lsSegmentsStore = useLfSegmentsStore();
const { selectedProjectGroup } = storeToRefs(lsSegmentsStore);
const organization = computed(() => activeOrganization(props.contributor));
const jobTitle = computed(() => props.contributor.attributes.jobTitle?.default
|| organization.value?.memberOrganizations?.title);
const organization = computed(() => props.contributor.organizations?.[0]);
const jobTitle = computed(() => organization.value?.memberOrganizations?.title
|| props.contributor.attributes.jobTitle?.default);
</script>

<script lang="ts">
Expand Down
39 changes: 1 addition & 38 deletions frontend/src/modules/contributor/helpers/contributor.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,44 +66,7 @@ const useContributorHelpers = () => {
}));
};

const activeOrganization = (contributor: Contributor) => {
const { organizations } = contributor;

// No active organization
if (!organizations?.length) {
return null;
}

// Only one organization that doesn't have either start or end date
// We assume it's the active organization
if (organizations.length === 1
&& !organizations[0].memberOrganizations?.dateStart
&& !organizations[0].memberOrganizations?.dateEnd) {
return organizations[0];
}

// Get all organizations that have a start date but not an end date (present)
const completeOrganizations = organizations
.filter((organization) => !!organization.memberOrganizations?.dateStart && !organization.memberOrganizations?.dateEnd);

// Return the most recent organization, comparing the startDate
const mostRecent = completeOrganizations.reduce((mostRecent, organization) => {
const mostRecentStartDate = new Date(mostRecent.memberOrganizations?.dateStart);
const organizationStartDate = new Date(organization.memberOrganizations?.dateStart);

if (organizationStartDate > mostRecentStartDate) {
return organization;
}

return mostRecent;
}, completeOrganizations.length ? completeOrganizations[0] : null);

if (mostRecent) {
return mostRecent;
}

return organizations[0];
};
const activeOrganization = (contributor: Contributor) => contributor.organizations?.[0];

return {
avatar,
Expand Down

0 comments on commit b156392

Please sign in to comment.