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

Revert this part of refactoring for now #877

Closed
wants to merge 1 commit into from
Closed
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
32 changes: 31 additions & 1 deletion frontend/src/routes/(app)/(internal)/libraries/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,36 @@ export const actions: Actions = {
}
},
delete: async (event) => {
return nestedDeleteFormAction({ event });
const formData = await event.request.formData();
const schema = z.object({ id: z.string().regex(URN_REGEX) });
const deleteForm = await superValidate(formData, zod(schema));

const URLModel = formData.get('urlmodel');

const id = deleteForm.data.id;
const endpoint = `${BASE_API_URL}/${URLModel}/${id}/`;

if (!deleteForm.valid) {
console.error(deleteForm.errors);
return fail(400, { form: deleteForm });
}

if (formData.has('delete')) {
const requestInitOptions: RequestInit = {
method: 'DELETE'
};
const res = await event.fetch(endpoint, requestInitOptions);
if (!res.ok) {
const response = await res.json();
console.error(response);
setFlash({ type: 'error', message: `${response}` }, event);
if (response.non_field_errors) {
setError(deleteForm, 'non_field_errors', response.non_field_errors);
}
return fail(400, { form: deleteForm });
}
setFlash({ type: 'success', message: m.successfullyDeletedLibrary() }, event);
}
return { deleteForm };
}
};
4 changes: 3 additions & 1 deletion frontend/src/routes/(app)/(internal)/libraries/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
<ModelTable
source={data.storedLibrariesTable}
URLModel="libraries"
pagination={false}
pagination={true}
identifierField="urn"
deleteForm={data.deleteForm}
/>
{/if}
Expand All @@ -45,6 +46,7 @@
source={data.loadedLibrariesTable}
URLModel="libraries"
pagination={false}
identifierField="urn"
deleteForm={data.deleteForm}
detailQueryParameter="loaded"
/>
Expand Down
Loading