Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dashboard): payout create form hiding users with positive balance #502

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
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
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
Loading