import { component$, useStore, useSignal, $ } from '@builder.io/qwik' import { getErrorHtml } from '~/utils/getErrorHtml/getErrorHtml' import { getDatabase } from 'wildebeest/backend/src/database' import { action$, Form, zod$, z } from '@builder.io/qwik-city' import { addAlias } from 'wildebeest/backend/src/accounts/alias' const zodSchema = zod$({ alias: z.string().min(1), }) export const action = action$(async (data, { platform, html }) => { const db = await getDatabase(platform) const connectedActor = platform.data.connectedActor if (connectedActor === null) { throw html(500, getErrorHtml('user not present in context')) } let success = false try { await addAlias(db, data.alias, connectedActor) success = true } catch (e: unknown) { success = false } return { success, } }, zodSchema) export default component$(() => { const state = useStore({ alias: '' }) const toast = useSignal<'success' | 'failure' | null>(null) const handleInput = $((event: Event) => { state.alias = (event.target as HTMLInputElement).value }) const saveAction = action() return (
) })