Skip to content

Commit

Permalink
fix: disable private calendar option if user already has one
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Trost <[email protected]>
  • Loading branch information
galexrt committed Dec 22, 2024
1 parent 6d21648 commit 8e76047
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/components/calendar/CalendarCreateOrUpdateModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const { isOpen } = useModal();
const { attr, activeChar } = useAuth();
const calendarStore = useCalendarStore();
const { hasPrivateCalendar } = storeToRefs(calendarStore);
const notifications = useNotificatorStore();
Expand Down Expand Up @@ -50,7 +51,7 @@ type Schema = z.output<typeof schema>;
const state = reactive<Schema>({
name: '',
description: '',
private: true,
private: !hasPrivateCalendar,
public: false,
closed: false,
color: 'primary',
Expand Down Expand Up @@ -181,7 +182,14 @@ const onSubmitThrottle = useThrottleFn(async (event: FormSubmitEvent<Schema>) =>
:label="$t('components.calendar.CalendarCreateOrUpdateModal.private')"
class="flex-1"
>
<UToggle v-model="state.private" :disabled="!canDo.privateCalendar || calendarId !== undefined" />
<UToggle
v-model="state.private"
:disabled="
!canDo.privateCalendar ||
calendarId !== undefined ||
(!props.calendarId && hasPrivateCalendar)
"
/>
</UFormGroup>

<UFormGroup v-if="canDo.publicCalendar" name="public" :label="$t('common.public')" class="flex-1">
Expand Down
6 changes: 6 additions & 0 deletions app/store/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,12 @@ export const useCalendarStore = defineStore('calendar', {
}
},
},
getters: {
hasPrivateCalendar: (state) => {
const { activeChar } = useAuth();
return !!state.calendars.find((c) => c.job === undefined && c.creatorId === activeChar.value?.userId);
},
},
});

class CalendarDexie extends Dexie {
Expand Down

0 comments on commit 8e76047

Please sign in to comment.