Skip to content

Commit

Permalink
open dialog on button edit
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume_Bernier committed Apr 17, 2024
1 parent 261a3c6 commit 6464c73
Showing 1 changed file with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,44 @@
import { type Transactions, transactionSchema } from './schemas';
import { Button } from '$lib/components/ui/button';
import * as DropdownMenu from '$lib/components/ui/dropdown-menu';
import {
currentSelectedTransaction,
isDialogOpen
} from '../../../../../routes/(app)/admin/transactions/store';
export let row: Transactions;
const transaction = transactionSchema.parse(row);
async function openDocument(e: Event) {
e.preventDefault();
const formData = new FormData();
formData.append('download', transaction.id);
e.preventDefault();
const formData = new FormData();
formData.append('download', transaction.id);
try {
const response = await fetch('?/downloadDocument', {
method: 'POST',
body: formData
});
const result = await response.json();
try {
const response = await fetch('?/downloadDocument', {
method: 'POST',
body: formData
});
const result = await response.json();
const dataObject = JSON.parse(result.data);
const url = dataObject[3];
if (url) {
window.open(url, '_blank');
} else {
console.error('URL not found in the response:', result);
}
} catch (error) {
console.error('Failed to fetch:', error);
}
}
window.open(url, '_blank');
} else {
console.error('URL not found in the response:', result);
}
} catch (error) {
console.error('Failed to fetch:', error);
}
}
function editTransaction() {
return () => {
currentSelectedTransaction.set(transaction.id);
isDialogOpen.set(true);
};
}
</script>

<DropdownMenu.Root>
Expand All @@ -45,7 +56,9 @@
</Button>
</DropdownMenu.Trigger>
<DropdownMenu.Content class="w-[160px]" align="end">
<DropdownMenu.Item>Edit</DropdownMenu.Item>
<button on:click={editTransaction()} class="w-full">
<DropdownMenu.Item>Edit</DropdownMenu.Item>
</button>
<form method="POST" action="?/downloadDocument" on:submit={openDocument}>
<input hidden value={transaction.id} name="download" />
<button type="submit" class="w-full">
Expand Down

0 comments on commit 6464c73

Please sign in to comment.