refactor: reflect formatForm changes to views

This commit is contained in:
axolotle 2024-07-25 11:16:38 +02:00
parent 4f59343614
commit 67ab4a2637
7 changed files with 31 additions and 38 deletions

View file

@ -465,10 +465,7 @@ export function useConfigPanels<NestedMV extends Obj, MV extends Obj<NestedMV>>(
} else { } else {
if (!(await v.value.form.$validate())) return if (!(await v.value.form.$validate())) return
} }
const data = await formatFormData(form, { const data = await formatForm(form, { removeNullish: true })
removeEmpty: false,
removeNull: true,
})
onPanelApply({ panelId, data, action }, onErrorFn) onPanelApply({ panelId, data, action }, onErrorFn)
} }

View file

@ -14,7 +14,7 @@ import {
required, required,
sameAs, sameAs,
} from '@/helpers/validators' } from '@/helpers/validators'
import { formatFormData } from '@/helpers/yunohostArguments' import { formatForm } from '@/helpers/yunohostArguments'
import type { FieldProps, FormFieldDict } from '@/types/form' import type { FieldProps, FormFieldDict } from '@/types/form'
import LoginView from '@/views/LoginView.vue' import LoginView from '@/views/LoginView.vue'
import { DomainForm } from '@/views/_partials' import { DomainForm } from '@/views/_partials'
@ -100,15 +100,17 @@ const setUser = onSubmit(async () => {
}) })
async function performPostInstall(force = false) { async function performPostInstall(force = false) {
// FIXME update formatFormData to unwrap ref auto
const { username, fullname, password } = form.value const { username, fullname, password } = form.value
const data = await formatFormData({ const data = await formatForm(
domain: domain.value, {
dyndns_recovery_password: dyndns_recovery_password.value, domain: domain.value,
username, dyndns_recovery_password: dyndns_recovery_password.value,
fullname, username,
password, fullname,
}) password,
},
{ removeEmpty: true },
)
// FIXME does the api will throw an error for bad passwords ? // FIXME does the api will throw an error for bad passwords ?
api api

View file

@ -11,7 +11,7 @@ import {
required, required,
sameAs, sameAs,
} from '@/helpers/validators' } from '@/helpers/validators'
import { formatFormData } from '@/helpers/yunohostArguments' import { formatForm } from '@/helpers/yunohostArguments'
import { useStoreGetters } from '@/store/utils' import { useStoreGetters } from '@/store/utils'
import type { AdressModelValue, FieldProps, FormFieldDict } from '@/types/form' import type { AdressModelValue, FieldProps, FormFieldDict } from '@/types/form'
@ -31,7 +31,7 @@ const props = withDefaults(
}, },
) )
const emit = defineEmits<{ const emit = defineEmits<{
submit: [data: { domain: string; dyndns_recovery_password: string }] submit: [data: Partial<{ domain: string; dyndns_recovery_password: string }>]
}>() }>()
const { t } = useI18n() const { t } = useI18n()
@ -169,11 +169,14 @@ const onDomainAdd = onSubmit(async () => {
const domainType = selected.value const domainType = selected.value
if (!domainType) return if (!domainType) return
const data = await formatFormData({ const data = await formatForm(
domain: form.value[domainType], {
dyndns_recovery_password: domain: form.value[domainType],
domainType === 'dynDomain' ? form.value.dynDomainPassword : '', dyndns_recovery_password:
}) domainType === 'dynDomain' ? form.value.dynDomainPassword : '',
},
{ removeEmpty: true },
)
emit('submit', data) emit('submit', data)
}) })
</script> </script>

View file

@ -9,7 +9,7 @@ import { APIBadRequestError, type APIError } from '@/api/errors'
import { useAutoModal } from '@/composables/useAutoModal' import { useAutoModal } from '@/composables/useAutoModal'
import { useInitialQueries } from '@/composables/useInitialQueries' import { useInitialQueries } from '@/composables/useInitialQueries'
import { import {
formatFormData, formatForm,
formatI18nField, formatI18nField,
formatYunoHostArguments, formatYunoHostArguments,
} from '@/helpers/yunohostArguments' } from '@/helpers/yunohostArguments'
@ -174,11 +174,7 @@ async function performInstall() {
if (!confirmed) return if (!confirmed) return
} }
const { data: args, label } = await formatFormData(form, { const { label, ...args } = await formatForm(form, { removeNullish: true })
extract: ['label'],
removeEmpty: false,
removeNull: true,
})
const data = { const data = {
app: props.id, app: props.id,
label, label,

View file

@ -15,7 +15,7 @@ import {
sameAs, sameAs,
unique, unique,
} from '@/helpers/validators' } from '@/helpers/validators'
import { formatFormData } from '@/helpers/yunohostArguments' import { formatForm } from '@/helpers/yunohostArguments'
import { useStoreGetters } from '@/store/utils' import { useStoreGetters } from '@/store/utils'
import type { FieldProps, FormFieldDict } from '@/types/form' import type { FieldProps, FormFieldDict } from '@/types/form'
@ -115,7 +115,7 @@ function onQueriesResponse() {
} }
const onUserCreate = onSubmit(async (onError) => { const onUserCreate = onSubmit(async (onError) => {
const data = await formatFormData(form.value, { flatten: true }) const data = await formatForm(form)
api api
.post({ uri: 'users' }, data, { .post({ uri: 'users' }, data, {
key: 'users.create', key: 'users.create',

View file

@ -18,11 +18,7 @@ import {
required, required,
sameAs, sameAs,
} from '@/helpers/validators' } from '@/helpers/validators'
import { import { formatAdress, formatForm, sizeToM } from '@/helpers/yunohostArguments'
formatAdress,
formatFormData,
sizeToM,
} from '@/helpers/yunohostArguments'
import { useStoreGetters } from '@/store/utils' import { useStoreGetters } from '@/store/utils'
import type { AdressModelValue, FieldProps, FormFieldDict } from '@/types/form' import type { AdressModelValue, FieldProps, FormFieldDict } from '@/types/form'
@ -172,9 +168,8 @@ function onQueriesResponse(user_: any) {
} }
const onUserEdit = onSubmit(async (onError, serverErrors) => { const onUserEdit = onSubmit(async (onError, serverErrors) => {
const { data: formData } = await formatFormData(form.value, { const { username: _, ...formData } = await formatForm(form, {
flatten: true, removeEmpty: true,
extract: ['username'],
}) })
// FIXME not sure computed can be executed? // FIXME not sure computed can be executed?
const user_ = user.value(props.name) const user_ = user.value(props.name)

View file

@ -8,7 +8,7 @@ import api from '@/api'
import { useForm } from '@/composables/form' import { useForm } from '@/composables/form'
import { useAutoModal } from '@/composables/useAutoModal' import { useAutoModal } from '@/composables/useAutoModal'
import { required } from '@/helpers/validators' import { required } from '@/helpers/validators'
import { formatFormData } from '@/helpers/yunohostArguments' import { formatForm } from '@/helpers/yunohostArguments'
import type { FieldProps, FileModelValue, FormFieldDict } from '@/types/form' import type { FieldProps, FileModelValue, FormFieldDict } from '@/types/form'
const { t } = useI18n() const { t } = useI18n()
@ -68,7 +68,7 @@ const onUserImport = onSubmit(async (onError) => {
const requestArgs = { ...form.value } as Partial<Form> const requestArgs = { ...form.value } as Partial<Form>
if (!requestArgs.delete) delete requestArgs.delete if (!requestArgs.delete) delete requestArgs.delete
if (!requestArgs.update) delete requestArgs.update if (!requestArgs.update) delete requestArgs.update
const data = await formatFormData(requestArgs) const data = await formatForm(requestArgs)
api api
.post('users/import', data, null, { asFormData: true }) .post('users/import', data, null, { asFormData: true })
.then(() => { .then(() => {