Skip to content

Commit 8b7c3ac

Browse files
author
Lasim
committed
feat(frontend): simplify checkbox value update handling in settings
1 parent 448e687 commit 8b7c3ac

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed
Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
<script setup lang="ts">
2-
import type { CheckboxRootEmits, CheckboxRootProps } from "reka-ui"
3-
import type { HTMLAttributes } from "vue"
4-
import { reactiveOmit } from "@vueuse/core"
5-
import { Check } from "lucide-vue-next"
6-
import { CheckboxIndicator, CheckboxRoot, useForwardPropsEmits } from "reka-ui"
7-
import { cn } from "@/lib/utils"
2+
interface Props {
3+
checked?: boolean
4+
disabled?: boolean
5+
id?: string
6+
name?: string
7+
}
88
9-
const props = defineProps<CheckboxRootProps & { class?: HTMLAttributes["class"] }>()
10-
const emits = defineEmits<CheckboxRootEmits>()
9+
const props = withDefaults(defineProps<Props>(), {
10+
checked: false,
11+
disabled: false,
12+
})
1113
12-
const delegatedProps = reactiveOmit(props, "class")
14+
const emit = defineEmits<{
15+
'update:checked': [value: boolean]
16+
}>()
1317
14-
const forwarded = useForwardPropsEmits(delegatedProps, emits)
18+
function handleChange(event: Event) {
19+
const target = event.target as HTMLInputElement
20+
emit('update:checked', target.checked)
21+
}
1522
</script>
1623

1724
<template>
18-
<CheckboxRoot
19-
v-bind="forwarded"
20-
:class="
21-
cn('grid place-content-center peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground',
22-
props.class)"
23-
>
24-
<CheckboxIndicator class="grid place-content-center text-current">
25-
<slot>
26-
<Check class="h-4 w-4" />
27-
</slot>
28-
</CheckboxIndicator>
29-
</CheckboxRoot>
25+
<input
26+
type="checkbox"
27+
:id="props.id"
28+
:name="props.name"
29+
:checked="props.checked"
30+
:disabled="props.disabled"
31+
@change="handleChange"
32+
class="size-4 cursor-pointer accent-primary"
33+
/>
3034
</template>

services/frontend/src/views/admin/settings/[type].vue

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ function handleConnectionTested(result: { success: boolean; message: string }) {
146146
// Reactive form values
147147
const formValues = ref<Record<string, string | number | boolean>>({})
148148
149+
// Update boolean setting value
150+
function updateBooleanValue(key: string, value: boolean) {
151+
formValues.value[key] = value
152+
}
153+
149154
// Create initial form values from settings
150155
function createInitialValues(settings: Setting[]) {
151156
const values: Record<string, string | number | boolean> = {}
@@ -370,14 +375,12 @@ async function handleSubmit(event: Event) {
370375
<Checkbox
371376
:id="`setting-${setting.key}`"
372377
:checked="formValues[setting.key] as boolean"
373-
@update:checked="(value: boolean) => {
374-
formValues[setting.key] = value
375-
}"
378+
@update:checked="(value: boolean) => updateBooleanValue(setting.key, value)"
376379
/>
377380
<div class="grid gap-1">
378381
<label
379382
:for="`setting-${setting.key}`"
380-
class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
383+
class="cursor-pointer text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
381384
>
382385
{{ setting.name || setting.key }}
383386
</label>
@@ -451,14 +454,12 @@ async function handleSubmit(event: Event) {
451454
<Checkbox
452455
:id="`setting-${setting.key}-desktop`"
453456
:checked="formValues[setting.key] as boolean"
454-
@update:checked="(value: boolean) => {
455-
formValues[setting.key] = value
456-
}"
457+
@update:checked="(value: boolean) => updateBooleanValue(setting.key, value)"
457458
/>
458459
<div class="grid gap-1">
459460
<label
460461
:for="`setting-${setting.key}-desktop`"
461-
class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
462+
class="cursor-pointer text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
462463
>
463464
{{ setting.name || setting.key }}
464465
</label>

0 commit comments

Comments
 (0)