Skip to content

Commit

Permalink
add edit team function
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiritin committed Aug 14, 2024
1 parent caa11f5 commit 85510e5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/Http/Requests/Groups/GroupUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public function rules(): array
{
return [
'description' => ['nullable','string','max:10000'],
'name' => ['required','string','max:255'],
];
}

Expand Down
2 changes: 1 addition & 1 deletion app/Policies/GroupUserPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class GroupUserPolicy

public function view(User $user, GroupUser $groupUser): bool
{
return ($user->scopeCheck('groups.read') && $groupUser->isMember());
return ($user->scopeCheck('groups.read') && ($groupUser->isMember() || $groupUser->group->parent?->isMember($user)));
}

public function update(User $user, GroupUser $groupUserInitiator): bool
Expand Down
30 changes: 30 additions & 0 deletions resources/js/Pages/Staff/Groups/Tabs/TabHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const props = defineProps({
const showAddMemberDialog = ref(false);
const showAddTeamDialog = ref(false);
const confirmDeleteTeamDialog = ref(false);
const showEditTeamDialog = ref(false);
const toast = useToast();
function submitUserForm() {
Expand Down Expand Up @@ -48,6 +49,16 @@ function submitTeamForm() {
});
}
function submitEditTeamForm() {
editTeamForm.submit({
preserveScroll: true,
onSuccess: () => {
showEditTeamDialog.value = false;
toast.add({severity: 'success', summary: 'Success', detail: 'Team updated'});
}
});
}
const staffMemberList = usePage().props.staffMemberList;
const addUserForm = useForm('POST',route('staff.groups.members.store',{group: props.group.hashid}), {
Expand All @@ -59,6 +70,10 @@ const addTeamForm = useForm('POST',route('staff.groups.teams.store',{group: prop
name: '',
})
const editTeamForm = useForm('PATCH', route('staff.groups.update', {group: props.group.hashid}), {
name: props.group.name,
})
// watch showAddMemberDialog if closed, reset addUserForm
watch(showAddMemberDialog, (value) => {
if (!value) {
Expand Down Expand Up @@ -90,6 +105,9 @@ const options = ref(['Staff List', 'Email']);
<!-- Template Action -->
<template v-slot:action v-if="canEdit">
<div class="flex gap-2">
<Button
size="small"
@click="showEditTeamDialog = true">Edit Team</Button>
<Button
size="small"
@click="showAddMemberDialog = true">Add User
Expand Down Expand Up @@ -175,6 +193,18 @@ const options = ref(['Staff List', 'Email']);
</Button>
</div>
</Dialog>
<!-- Edit Team Name -->
<Dialog v-model:visible="showEditTeamDialog" modal class="max-w-md" header="Edit Team Name">
<form @submit.prevent="submitEditTeamForm()" class="space-y-3">
<label for="name">Team Name</label>
<InputText :invalid="editTeamForm.errors.name" v-model="editTeamForm.name" id="name" class="w-full"/>
<small class="text-red-500" v-if="editTeamForm.errors.name">{{ editTeamForm.errors.name }}</small>
<!-- Submit Button -->
<div class="flex justify-end">
<Button type="submit" class="btn btn-primary w-full">Save</Button>
</div>
</form>
</Dialog>
</template>

<style scoped>
Expand Down

0 comments on commit 85510e5

Please sign in to comment.