Skip to content

Commit

Permalink
fix(dashboard): payout create form hiding users with positive balance (
Browse files Browse the repository at this point in the history
  • Loading branch information
JustSamuel authored Feb 10, 2025
1 parent f4aa8cc commit 9002726
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
31 changes: 20 additions & 11 deletions apps/dashboard/src/components/FindUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@filter="filterUsers"
>
<template #option="slotProps" >
<span :class="{'text-gray-500': !isNegative(slotProps.option)}">
<span :class="{'text-gray-500': isNegative(slotProps.option) === true}">
{{ slotProps.option.fullName }} {{ slotProps.option.gewisId ? `(${slotProps.option.gewisId})` : '' }}
</span>
</template>
Expand Down Expand Up @@ -66,6 +66,19 @@ const userStore = useUserStore();
const loading = ref(false);
const users: Ref<(BaseUserResponse & { fullName: string })[]> = ref([]);
const compareBalance = (a: BaseUserResponse, b: BaseUserResponse) => {
const isANegative = isNegative(a);
const isBNegative = isNegative(b);
if (isANegative && !isBNegative) {
return -1;
}
if (!isANegative && isBNegative) {
return 1;
}
return 0;
};
const transformUsers = (userData: BaseUserResponse[]) => {
const usersData: (BaseUserResponse & { fullName: string})[]
= userData.map((user) => ({
Expand All @@ -74,18 +87,12 @@ const transformUsers = (userData: BaseUserResponse[]) => {
}));
usersData.sort((a, b) => {
const isANegative = isNegative(a);
const isBNegative = isNegative(b);
if (isANegative && !isBNegative) {
return -1;
}
if (!isANegative && isBNegative) {
return 1;
if (!props.showPositive) {
const res = compareBalance(a, b);
if (res !== 0) return res;
}
return a.fullName.localeCompare(b.fullName);
});
return usersData;
};
Expand All @@ -107,7 +114,9 @@ const filterUsers = (e: any) => {
};
function isNegative(user: BaseUserResponse) {
return userStore.getBalanceById(user.id).amount.amount < 0;
const balance = userStore.getBalanceById(user.id);
if (!balance) return undefined;
else return balance.amount.amount < 0;
}
onMounted(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
:value="form.model.user.value.value"
@update:value="form.context.setFieldValue('user', $event)"
:errors="form.context.errors.value.user"
:show-positive="true"
id="name" placeholder="John Doe"/>

<!-- TODO think about turning this into a component? -->
Expand Down

0 comments on commit 9002726

Please sign in to comment.