From cda024ca6f9008ff4b9b692845a2f892ef2a84f5 Mon Sep 17 00:00:00 2001 From: ditatompel Date: Tue, 7 May 2024 23:42:35 +0700 Subject: [PATCH] Use modal window for add prober form The previous add prober is using new page to show add prober form. In this commit, the add prober form is using modal so it can be more simpler. --- .../routes/(loggedin)/app/prober/+page.svelte | 37 +++++++- .../(loggedin)/app/prober/add/+page.svelte | 94 ------------------- .../(loggedin)/app/prober/api-handler.js | 21 ++++- handler/routes.go | 2 +- 4 files changed, 52 insertions(+), 102 deletions(-) delete mode 100644 frontend/src/routes/(loggedin)/app/prober/add/+page.svelte diff --git a/frontend/src/routes/(loggedin)/app/prober/+page.svelte b/frontend/src/routes/(loggedin)/app/prober/+page.svelte index 51567cb..57488f8 100644 --- a/frontend/src/routes/(loggedin)/app/prober/+page.svelte +++ b/frontend/src/routes/(loggedin)/app/prober/+page.svelte @@ -1,7 +1,7 @@ - -
-

Add Prober

-
-{#if !isProcessing} - {#if formResult?.status === 'error'} - - {/if} - {#if formResult?.status === 'ok'} - - {/if} -{:else} - - -{/if} -
-
-
-
- -
-
- - -
-
diff --git a/frontend/src/routes/(loggedin)/app/prober/api-handler.js b/frontend/src/routes/(loggedin)/app/prober/api-handler.js index bd40b38..a3e257b 100644 --- a/frontend/src/routes/(loggedin)/app/prober/api-handler.js +++ b/frontend/src/routes/(loggedin)/app/prober/api-handler.js @@ -8,10 +8,14 @@ export const loadData = async (state) => { return json.data.items ?? []; }; -export const deleteData = async (id) => { - const response = await fetch(apiUri(`/api/v1/prober/${id}`), { - method: 'DELETE', - credentials: 'include' +export const createProber = async (name) => { + const response = await fetch(apiUri('/api/v1/prober'), { + method: 'POST', + credentials: 'include', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ name }) }); const json = await response.json(); return json; @@ -30,6 +34,15 @@ export const editProber = async (id, name) => { return json; }; +export const deleteProber = async (id) => { + const response = await fetch(apiUri(`/api/v1/prober/${id}`), { + method: 'DELETE', + credentials: 'include' + }); + const json = await response.json(); + return json; +}; + const getParams = ({ pageNumber, rowsPerPage, sort, filters }) => { let params = `page=${pageNumber}&limit=${rowsPerPage}`; diff --git a/handler/routes.go b/handler/routes.go index cfa493f..032ea5f 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -13,7 +13,7 @@ func V1Api(app *fiber.App) { v1 := app.Group("/api/v1") v1.Get("/prober", Prober) - v1.Post("/prober", Prober) + v1.Post("/prober", CookieProtected, Prober) v1.Patch("/prober/:id", CookieProtected, Prober) v1.Delete("/prober/:id", CookieProtected, Prober) v1.Get("/nodes", MoneroNodes)