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

Fix booking link toggle in schedule creation #697

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion frontend/src/components/ScheduleCreation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ watch(
<switch-toggle
class="my-1 text-sm font-medium text-gray-500 dark:text-gray-300"
name="booking_confirmation"
:active="schedule.booking_confirmation"
:active="scheduleInput.booking_confirmation"
:label="t('label.bookingConfirmation')"
:disabled="!scheduleInput.active"
@changed="toggleBookingConfirmation"
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/tbpro/elements/SwitchToggle.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { ref, onMounted, watch } from 'vue';
import { useI18n } from 'vue-i18n';

// component constants
Expand Down Expand Up @@ -29,6 +29,15 @@ const toggleState = () => {
emit('changed', state.value);
}
};

// Update state if parent changes active prop
// e.g. after initializing async data
watch(
() => props.active,
() => {
state.value = props.active;
}
);
Copy link
Member

Choose a reason for hiding this comment

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

I think you might be able to {active} = toRef(props) instead of this.

Copy link
Collaborator Author

@devmount devmount Sep 27, 2024

Choose a reason for hiding this comment

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

Actually I tried const state = toRef(props.active); but it won't properly initialize state on page load (it uses the default value instead of the parents prop when i async loaded everything)... 😅 Or I'm just to stupid to properly implement this 😂 Maybe I oversaw sth?

Copy link
Member

Choose a reason for hiding this comment

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

Oh I think you need to toRef props itself and destructing assign active.

so { active } = toRef(props);

but i can take a look on tuesday!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, you mean toRefs() (with an 's')? OR actually toRef()? I tried the former too but it complained about being read-only when updating that ref 😂

Copy link
Member

Choose a reason for hiding this comment

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

This works for now 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

haha alright! thanks

</script>

<template>
Expand Down