hide create project buttons and modal depending on the permission

This commit is contained in:
Gregor Vostrak
2024-10-28 13:37:39 +01:00
parent eb4debe481
commit cd7573dcf1
11 changed files with 29 additions and 2 deletions

View File

@@ -28,6 +28,7 @@ import type {
import { useClientsStore } from '@/utils/useClients'; import { useClientsStore } from '@/utils/useClients';
import TimePicker from '@/packages/ui/src/Input/TimePicker.vue'; import TimePicker from '@/packages/ui/src/Input/TimePicker.vue';
import { getOrganizationCurrencyString } from '@/utils/money'; import { getOrganizationCurrencyString } from '@/utils/money';
import { canCreateProjects } from '@/utils/permissions';
const projectStore = useProjectsStore(); const projectStore = useProjectsStore();
const { projects } = storeToRefs(projectStore); const { projects } = storeToRefs(projectStore);
const taskStore = useTasksStore(); const taskStore = useTasksStore();
@@ -134,6 +135,7 @@ async function createTag(tag: string) {
:clients :clients
:createProject :createProject
:createClient :createClient
:canCreateProject="canCreateProjects()"
:currency="getOrganizationCurrencyString()" :currency="getOrganizationCurrencyString()"
class="mt-1" class="mt-1"
size="xlarge" size="xlarge"

View File

@@ -25,6 +25,7 @@ import TimeTrackerRunningInDifferentOrganizationOverlay from '@/packages/ui/src/
import { useClientsStore } from '@/utils/useClients'; import { useClientsStore } from '@/utils/useClients';
import { getOrganizationCurrencyString } from '@/utils/money'; import { getOrganizationCurrencyString } from '@/utils/money';
import { isAllowedToPerformPremiumAction } from '@/utils/billing'; import { isAllowedToPerformPremiumAction } from '@/utils/billing';
import { canCreateProjects } from '@/utils/permissions';
const page = usePage<{ const page = usePage<{
auth: { auth: {
@@ -113,6 +114,7 @@ const { tags } = storeToRefs(useTagsStore());
<TimeTrackerControls <TimeTrackerControls
:createProject :createProject
:enableEstimatedTime="isAllowedToPerformPremiumAction()" :enableEstimatedTime="isAllowedToPerformPremiumAction()"
:canCreateProject="canCreateProjects()"
:createClient :createClient
:clients :clients
:tags :tags

View File

@@ -66,6 +66,7 @@ import { getCurrentOrganizationId } from '@/utils/useUser';
import { useTimeEntriesStore } from '@/utils/useTimeEntries'; import { useTimeEntriesStore } from '@/utils/useTimeEntries';
import TimeEntryMassActionRow from '@/packages/ui/src/TimeEntry/TimeEntryMassActionRow.vue'; import TimeEntryMassActionRow from '@/packages/ui/src/TimeEntry/TimeEntryMassActionRow.vue';
import { isAllowedToPerformPremiumAction } from '@/utils/billing'; import { isAllowedToPerformPremiumAction } from '@/utils/billing';
import { canCreateProjects } from '@/utils/permissions';
const startDate = useSessionStorage<string>( const startDate = useSessionStorage<string>(
'reporting-start-date', 'reporting-start-date',
@@ -340,6 +341,7 @@ async function clearSelectionAndState() {
</div> </div>
<TimeEntryMassActionRow <TimeEntryMassActionRow
:selected-time-entries="selectedTimeEntries" :selected-time-entries="selectedTimeEntries"
:canCreateProject="canCreateProjects()"
:enableEstimatedTime="isAllowedToPerformPremiumAction()" :enableEstimatedTime="isAllowedToPerformPremiumAction()"
@submit="clearSelectionAndState" @submit="clearSelectionAndState"
:delete-selected="deleteSelected" :delete-selected="deleteSelected"
@@ -366,6 +368,7 @@ async function clearSelectionAndState() {
<TimeEntryRow <TimeEntryRow
:selected="selectedTimeEntries.includes(entry)" :selected="selectedTimeEntries.includes(entry)"
@selected="selectedTimeEntries.push(entry)" @selected="selectedTimeEntries.push(entry)"
:canCreateProject="canCreateProjects()"
@unselected=" @unselected="
selectedTimeEntries = selectedTimeEntries.filter( selectedTimeEntries = selectedTimeEntries.filter(
(item) => item.id !== entry.id (item) => item.id !== entry.id

View File

@@ -29,6 +29,7 @@ import { getOrganizationCurrencyString } from '@/utils/money';
import TimeEntryMassActionRow from '@/packages/ui/src/TimeEntry/TimeEntryMassActionRow.vue'; import TimeEntryMassActionRow from '@/packages/ui/src/TimeEntry/TimeEntryMassActionRow.vue';
import type { UpdateMultipleTimeEntriesChangeset } from '@/packages/api/src'; import type { UpdateMultipleTimeEntriesChangeset } from '@/packages/api/src';
import { isAllowedToPerformPremiumAction } from '@/utils/billing'; import { isAllowedToPerformPremiumAction } from '@/utils/billing';
import { canCreateProjects } from '@/utils/permissions';
const timeEntriesStore = useTimeEntriesStore(); const timeEntriesStore = useTimeEntriesStore();
const { timeEntries, allTimeEntriesLoaded } = storeToRefs(timeEntriesStore); const { timeEntries, allTimeEntriesLoaded } = storeToRefs(timeEntriesStore);
@@ -142,6 +143,7 @@ function deleteSelected() {
<TimeEntryMassActionRow <TimeEntryMassActionRow
:selected-time-entries="selectedTimeEntries" :selected-time-entries="selectedTimeEntries"
:enableEstimatedTime="isAllowedToPerformPremiumAction()" :enableEstimatedTime="isAllowedToPerformPremiumAction()"
:canCreateProject="canCreateProjects()"
@submit="clearSelectionAndState" @submit="clearSelectionAndState"
:all-selected="selectedTimeEntries.length === timeEntries.length" :all-selected="selectedTimeEntries.length === timeEntries.length"
@select-all="selectedTimeEntries = [...timeEntries]" @select-all="selectedTimeEntries = [...timeEntries]"
@@ -166,6 +168,7 @@ function deleteSelected() {
v-model:selected="selectedTimeEntries" v-model:selected="selectedTimeEntries"
:createProject :createProject
:enableEstimatedTime="isAllowedToPerformPremiumAction()" :enableEstimatedTime="isAllowedToPerformPremiumAction()"
:canCreateProject="canCreateProjects()"
:clients :clients
:createClient :createClient
:updateTimeEntry :updateTimeEntry

View File

@@ -40,6 +40,7 @@ const props = defineProps<{
currency: string; currency: string;
selectedTimeEntries: TimeEntry[]; selectedTimeEntries: TimeEntry[];
enableEstimatedTime: boolean; enableEstimatedTime: boolean;
canCreateProject: boolean;
}>(); }>();
const emit = defineEmits<{ const emit = defineEmits<{
selected: [TimeEntry[]]; selected: [TimeEntry[]];
@@ -121,6 +122,7 @@ function onSelectChange(event: Event) {
:clients :clients
:createProject :createProject
:createClient :createClient
:canCreateProject
:projects="projects" :projects="projects"
:tasks="tasks" :tasks="tasks"
:showBadgeBorder="false" :showBadgeBorder="false"
@@ -177,6 +179,7 @@ function onSelectChange(event: Event) {
<TimeEntryRow <TimeEntryRow
:projects="projects" :projects="projects"
:enableEstimatedTime :enableEstimatedTime
:canCreateProject
:tasks="tasks" :tasks="tasks"
:selected=" :selected="
!!selectedTimeEntries.find( !!selectedTimeEntries.find(

View File

@@ -38,6 +38,7 @@ const props = defineProps<{
createClient: (client: CreateClientBody) => Promise<Client | undefined>; createClient: (client: CreateClientBody) => Promise<Client | undefined>;
currency: string; currency: string;
enableEstimatedTime: boolean; enableEstimatedTime: boolean;
canCreateProject: boolean;
}>(); }>();
const groupedTimeEntries = computed(() => { const groupedTimeEntries = computed(() => {
@@ -161,6 +162,7 @@ function unselectAllTimeEntries(value: TimeEntriesGroupedByType[]) {
<template v-for="entry in value" :key="entry.id"> <template v-for="entry in value" :key="entry.id">
<TimeEntryAggregateRow <TimeEntryAggregateRow
:createProject :createProject
:canCreateProject
:enableEstimatedTime :enableEstimatedTime
:selected-time-entries="selectedTimeEntries" :selected-time-entries="selectedTimeEntries"
@selected=" @selected="
@@ -197,6 +199,7 @@ function unselectAllTimeEntries(value: TimeEntriesGroupedByType[]) {
<TimeEntryRow <TimeEntryRow
:createClient :createClient
:enableEstimatedTime :enableEstimatedTime
:canCreateProject
:createProject :createProject
:projects="projects" :projects="projects"
:selected=" :selected="

View File

@@ -33,6 +33,7 @@ const props = defineProps<{
) => Promise<void>; ) => Promise<void>;
currency: string; currency: string;
enableEstimatedTime: boolean; enableEstimatedTime: boolean;
canCreateProject: boolean;
}>(); }>();
const emit = defineEmits<{ const emit = defineEmits<{
@@ -55,6 +56,7 @@ const showMassUpdateModal = ref(false);
:createClient :createClient
:updateTimeEntries :updateTimeEntries
:enableEstimatedTime :enableEstimatedTime
:canCreateProject
:currency :currency
:time-entries="selectedTimeEntries" :time-entries="selectedTimeEntries"
@submit="emit('submit')" @submit="emit('submit')"

View File

@@ -36,6 +36,7 @@ const props = defineProps<{
) => Promise<void>; ) => Promise<void>;
currency: string; currency: string;
enableEstimatedTime: boolean; enableEstimatedTime: boolean;
canCreateProject: boolean;
}>(); }>();
const emit = defineEmits<{ const emit = defineEmits<{
@@ -156,6 +157,7 @@ watch(removeAllTags, () => {
:createProject :createProject
:createClient :createClient
:currency="currency" :currency="currency"
:canCreateProject
class="mt-1" class="mt-1"
empty-placeholder="Select project..." empty-placeholder="Select project..."
allow-reset allow-reset

View File

@@ -38,6 +38,7 @@ const props = defineProps<{
showMember?: boolean; showMember?: boolean;
showDate?: boolean; showDate?: boolean;
selected?: boolean; selected?: boolean;
canCreateProject: boolean;
enableEstimatedTime: boolean; enableEstimatedTime: boolean;
}>(); }>();
@@ -111,6 +112,7 @@ function onSelectChange(event: Event) {
<TimeTrackerProjectTaskDropdown <TimeTrackerProjectTaskDropdown
:createProject :createProject
:createClient :createClient
:canCreateProject
:clients :clients
:projects="projects" :projects="projects"
:tasks="tasks" :tasks="tasks"

View File

@@ -34,6 +34,7 @@ const props = defineProps<{
isActive: boolean; isActive: boolean;
currency: string; currency: string;
enableEstimatedTime: boolean; enableEstimatedTime: boolean;
canCreateProject: boolean;
}>(); }>();
const emit = defineEmits<{ const emit = defineEmits<{
@@ -110,6 +111,7 @@ function updateTimeEntryDescription() {
class="flex items-center w-[130px] @2xl:w-auto shrink min-w-0"> class="flex items-center w-[130px] @2xl:w-auto shrink min-w-0">
<TimeTrackerProjectTaskDropdown <TimeTrackerProjectTaskDropdown
:createClient :createClient
:canCreateProject
:clients :clients
:createProject :createProject
:currency="currency" :currency="currency"

View File

@@ -64,6 +64,7 @@ const props = withDefaults(
emptyPlaceholder: string; emptyPlaceholder: string;
allowReset: boolean; allowReset: boolean;
enableEstimatedTime: boolean; enableEstimatedTime: boolean;
canCreateProject: boolean;
}>(), }>(),
{ {
showBadgeBorder: true, showBadgeBorder: true,
@@ -532,7 +533,7 @@ const showCreateProject = ref(false);
</script> </script>
<template> <template>
<div v-if="projects.length === 0"> <div v-if="projects.length === 0 && canCreateProject">
<Badge <Badge
@click="showCreateProject = true" @click="showCreateProject = true"
size="large" size="large"
@@ -689,7 +690,9 @@ const showCreateProject = ref(false);
</template> </template>
</template> </template>
</div> </div>
<div class="hover:bg-card-background-active rounded-b-lg"> <div
v-if="canCreateProject"
class="hover:bg-card-background-active rounded-b-lg">
<button <button
@click=" @click="
open = false; open = false;