Implement delete

This commit is contained in:
Adria Navarro 2025-03-17 15:26:48 +01:00
parent cbe9fba5a5
commit 6db7ea4458
3 changed files with 28 additions and 4 deletions

View File

@ -1,11 +1,20 @@
<script lang="ts">
import { ActionMenu, Icon, MenuItem } from "@budibase/bbui"
import { oauth2 } from "@/stores/builder"
import { ActionMenu, Icon, MenuItem, notifications } from "@budibase/bbui"
import type { OAuth2Config } from "@budibase/types"
export let row: OAuth2Config
function onEdit() {
// TODO
}
function onDelete() {
// TODO
async function onDelete() {
try {
await oauth2.delete(row.id)
notifications.success(`Config '${row.name}' deleted successfully`)
} catch (e: any) {
notifications.error("Error deleting config")
}
}
</script>

View File

@ -46,6 +46,11 @@ export class OAuth2Store extends BudiStore<OAuth2StoreState> {
await API.oauth2.create(config)
await this.fetch()
}
async delete(id: string) {
await API.oauth2.delete(id)
await this.fetch()
}
}
export const oauth2 = new OAuth2Store()

View File

@ -11,12 +11,12 @@ export interface OAuth2Endpoints {
create: (
config: UpsertOAuth2ConfigRequest
) => Promise<UpsertOAuth2ConfigResponse>
delete: (id: string) => Promise<void>
}
export const buildOAuth2Endpoints = (API: BaseAPIClient): OAuth2Endpoints => ({
/**
* Gets all OAuth2 configurations for the app.
* @param tableId the ID of the table
*/
fetch: async () => {
return (
@ -42,4 +42,14 @@ export const buildOAuth2Endpoints = (API: BaseAPIClient): OAuth2Endpoints => ({
},
})
},
/**
* Deletes an OAuth2 configuration by its id.
* @param id the ID of the OAuth2 config
*/
delete: async id => {
return await API.delete<void, void>({
url: `/api/oauth2/${id}`,
})
},
})