Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
</template>

<script setup>
import { reactive, ref, watch } from 'vue';
import {
computed, reactive, ref, watch,
} from 'vue';
import { CrowdIntegrations } from '@/integrations/integrations-config';

const emit = defineEmits(['update:modelValue']);
Expand Down Expand Up @@ -104,17 +106,30 @@ watch(
{ deep: true, immediate: true },
);

const existingIdentities = computed(() => (props.record?.identities || []).map((i) => ({
...i,
username: i.url ? i.url.split('/').at(-1) : '',
})));

watch(
model,
(value) => {
// Parse username object

const identities = value
.filter((i) => !Object.keys(identitiesForm).includes(i.platform) || !!i.username?.trim().length)
.map((i) => ({
...i,
name: i.username || i.name,
url: i.username?.length ? `https://${identitiesForm[i.platform]?.urlPrefix}${i.username}` : null,
}));
.map((i) => {
const existingOnes = existingIdentities.value.filter((id) => id.platform === i.platform);
const index = value
.filter((id) => id.platform === i.platform)
.findIndex((id) => id.username === i.username);
const existingOne = index >= 0 ? existingOnes[index] : null;
return {
...i,
name: !existingOne || existingOne.username !== i.username ? i.username || i.name : i.name,
url: i.username?.length ? `https://${identitiesForm[i.platform]?.urlPrefix}${i.username}` : null,
};
});

// Emit updated member
emit('update:modelValue', {
Expand Down