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

feat: export button functionality #5817

Merged
merged 3 commits into from
Feb 21, 2025
Merged
Changes from 2 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
36 changes: 34 additions & 2 deletions src/components/Portfolio/LoanFilterBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<kv-button
class="tw-text-sm"
variant="primary"
v-kv-track-event="['portfolio', 'click', 'export-loans']"
@click="handleExportClick"
>
Export {{ totalLoans }} loans
</kv-button>
Expand Down Expand Up @@ -55,18 +57,48 @@
</template>

<script setup>
import { ref } from 'vue';
import { ref, inject } from 'vue';
import { KvSelect, KvTextInput, KvButton } from '@kiva/kv-components';
import logReadQueryError from '#src/util/logReadQueryError';
import userIdQuery from '#src/graphql/query/userId.graphql';
import logFormatter from '#src/util/logFormatter';

defineProps({
const props = defineProps({
totalLoans: {
type: Number,
default: 0
}
});

const apollo = inject('apollo');
const searchText = ref('');
const selectedStatus = ref('all');
const selectedLocation = ref('all');
const selectedPartner = ref('all');

const handleExportClick = async () => {
try {
const { data } = await apollo.query({
query: userIdQuery
});

const userId = data?.my?.userAccount?.id;
if (!userId) {
logFormatter('No user ID available for export');
this.$showTipMsg('There was a problem preparing your loan export.', 'error');
return;
}

const queryParams = new URLSearchParams({
iDisplayStart: '0',
iDisplayLength: props.totalLoans.toString(),
user_id: userId.toString()
});

window.location.href = `https://www.kiva.org/portfolio/loans/export?${queryParams.toString()}`;
} catch (error) {
logReadQueryError(error, 'LoanFilterBar userIdQuery');
this.$showTipMsg('There was a problem preparing your loan export.', 'error');
}
};
</script>
Loading