Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ListboxInput component for selecting multiple options and use it for barbuddies #562

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions outsite.nl/components/pages/barbuddy/BarbuddyForm.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<i18n lang="yaml">
en:
success: The bar buddy you selected will contact you as soon as possible.
success: A bar buddy you selected will contact you as soon as possible.
nl:
success: Je barbuddy neemt zo snel mogelijk contact met je op.
success: Een barbuddy neemt zo snel mogelijk contact met je op.
</i18n>

<script setup>
Expand All @@ -12,19 +12,23 @@ const props = defineProps({
barBuddies: { type: Array, required: true },
})

const form = useReMemberForm('barbuddy', {
const form = useReMemberForm('barbuddy2', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, I forgot, why can't we use the old form still?

Since we're just comma seperating the bar buddies I think we could just as well stick them into the original barbuddy property

name: '',
age: '',
language: locale.value === 'nl' ? 'dutch' : 'english',
email: '',
phone_number: '',
pronouns: '',
barbuddy: 'no_preference',
buddy_preferences: 'no_preference',
buddies: [],
remarks: '',
})

const formElement = ref(null)
const submit = async () => {
if (form.fields.buddies.length > 0) {
form.fields.buddy_preferences = form.fields.buddies.join(', ')
}
await form.submit()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await form.submit()
await form.submit({
buddy_preferences: form.fields.buddies.join(', ') || 'no_preference'
})

I'd do something like this and remove the previous 3 lines + the property on line 22

window.scrollTo({ top: formElement.value.offsetTop, behavior: 'smooth' })
}
Expand Down Expand Up @@ -61,7 +65,7 @@ const barBuddyOptions = Object.fromEntries(props.barBuddies.map((buddy) => [budd
dutch: $t('forms.label.languages.dutch'),
english: $t('forms.label.languages.english'),
no_preference: $t('forms.label.languages.no_preference'),
}"
}"
/>
</ElementsFormElement>

Expand All @@ -70,13 +74,7 @@ const barBuddyOptions = Object.fromEntries(props.barBuddies.map((buddy) => [budd
</ElementsFormElement>

<ElementsFormElement name="barbuddy" :errors="form.validationErrors">
<ElementsFormRadioInput
v-model="form.fields.barbuddy"
:options="{
no_preference: $t('forms.label.languages.no_preference'),
...barBuddyOptions,
}"
/>
<ElementsFormListboxInput v-model="form.fields.buddies" :options="barBuddyOptions" />
</ElementsFormElement>

<ElementsFormElement name="remarks" :errors="form.validationErrors">
Expand Down
35 changes: 35 additions & 0 deletions shared/components/elements/form/ListboxInput.vue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, still surprised this works, awesome

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<script setup>
import { ref } from 'vue'
import {
Listbox,
ListboxLabel,
ListboxButton,
ListboxOptions,
Comment on lines +5 to +7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are unused

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and the ref import as well)

ListboxOption,
} from '@headlessui/vue'
import { IconCheckmark } from '@iconify-prerendered/vue-zondicons'


defineProps({
options: { type: Object, required: false },
})
const model = defineModel()
</script>

<template>
<Listbox v-model="model" multiple>
<div class="flex flex-wrap space-x-2">
<ListboxOption v-slot="{ selected }" v-for="[value, description] in Object.entries(options)" :key="value"
:value="value" as="template">
<button type="button" class="rounded-lg px-4 py-3 flex items-center transition-colors my-1"
:class="selected ? 'bg-gray-800 text-white' : 'bg-white text-gray-800 hover:bg-gray-300'">
{{ description }}
<div v-if="selected"
class="ml-2 w-5 h-5 rounded-full bg-white text-gray-800 flex items-center justify-center">
<IconCheckmark class="w-2 h-2" />
</div>
</button>
</ListboxOption>
</div>
</Listbox>
</template>