Browse Source

Extract dialog as BaseModal component

pull/341/head
Hironsan 5 years ago
parent
commit
ca864e14e2
5 changed files with 112 additions and 91 deletions
  1. 32
      frontend/components/containers/MemberAdditionButton.vue
  2. 37
      frontend/components/containers/MemberDeletionButton.vue
  3. 33
      frontend/components/containers/ProjectCreationButton.vue
  4. 37
      frontend/components/containers/ProjectDeletionButton.vue
  5. 64
      frontend/components/molecules/BaseModal.vue

32
frontend/components/containers/MemberAdditionButton.vue

@ -1,39 +1,33 @@
<template> <template>
<v-dialog
v-model="dialog"
width="800px"
<base-modal
text="Add Member"
:is-create="true"
> >
<template v-slot:activator="{ on }">
<v-btn
class="mb-2 text-capitalize"
color="primary"
@click="dialog=true"
>
Add Member
</v-btn>
<template v-slot="slotProps">
<member-addition-form
:add-member="addMember"
:items="items"
@close="slotProps.close"
@search-user="searchUser"
/>
</template> </template>
<member-addition-form
:add-member="addMember"
:items="items"
@close="dialog=false"
@search-user="searchUser"
/>
</v-dialog>
</base-modal>
</template> </template>
<script> <script>
import { mapActions } from 'vuex' import { mapActions } from 'vuex'
import BaseModal from '@/components/molecules/BaseModal'
import MemberAdditionForm from '@/components/organisms/MemberAdditionForm' import MemberAdditionForm from '@/components/organisms/MemberAdditionForm'
import UserService from '@/services/user.service' import UserService from '@/services/user.service'
export default { export default {
components: { components: {
BaseModal,
MemberAdditionForm MemberAdditionForm
}, },
data() { data() {
return { return {
dialog: false,
items: [] items: []
} }
}, },

37
frontend/components/containers/MemberDeletionButton.vue

@ -1,41 +1,29 @@
<template> <template>
<v-dialog
v-model="dialog"
width="800px"
<base-modal
text="Remove"
:disabled="!isMemberSelected"
> >
<template v-slot:activator="{ on }">
<v-btn
class="mb-2 ml-2 text-capitalize"
outlined
:disabled="!isMemberSelected"
@click="dialog=true"
>
Remove
</v-btn>
<template v-slot="slotProps">
<member-deletion-form
:selected="selected"
@remove="handleRemoveMember(); slotProps.close()"
@close="slotProps.close"
/>
</template> </template>
<member-deletion-form
:selected="selected"
@remove="handleRemoveMember"
@close="dialog=false"
/>
</v-dialog>
</base-modal>
</template> </template>
<script> <script>
import { mapState, mapGetters, mapActions } from 'vuex' import { mapState, mapGetters, mapActions } from 'vuex'
import BaseModal from '@/components/molecules/BaseModal'
import MemberDeletionForm from '@/components/organisms/MemberDeletionForm' import MemberDeletionForm from '@/components/organisms/MemberDeletionForm'
export default { export default {
components: { components: {
BaseModal,
MemberDeletionForm MemberDeletionForm
}, },
data() {
return {
dialog: false
}
},
computed: { computed: {
...mapState('members', ['selected']), ...mapState('members', ['selected']),
...mapGetters('members', ['isMemberSelected']) ...mapGetters('members', ['isMemberSelected'])
@ -47,7 +35,6 @@ export default {
handleRemoveMember() { handleRemoveMember() {
const projectId = this.$route.params.id const projectId = this.$route.params.id
this.removeMember(projectId) this.removeMember(projectId)
this.dialog = false
} }
} }
} }

33
frontend/components/containers/ProjectCreationButton.vue

@ -1,39 +1,28 @@
<template> <template>
<v-dialog
v-model="dialog"
width="800px"
<base-modal
text="Add Project"
:is-create="true"
> >
<template v-slot:activator="{ on }">
<v-btn
class="mb-2 text-capitalize"
color="primary"
@click="dialog=true"
>
Add Project
</v-btn>
<template v-slot="slotProps">
<project-creation-form
:create-project="createProject"
@close="slotProps.close"
/>
</template> </template>
<project-creation-form
:create-project="createProject"
@close="dialog=false"
/>
</v-dialog>
</base-modal>
</template> </template>
<script> <script>
import { mapActions } from 'vuex' import { mapActions } from 'vuex'
import BaseModal from '@/components/molecules/BaseModal'
import ProjectCreationForm from '@/components/organisms/ProjectCreationForm' import ProjectCreationForm from '@/components/organisms/ProjectCreationForm'
export default { export default {
components: { components: {
BaseModal,
ProjectCreationForm ProjectCreationForm
}, },
data() {
return {
dialog: false
}
},
methods: { methods: {
...mapActions('projects', ['createProject']) ...mapActions('projects', ['createProject'])
} }

37
frontend/components/containers/ProjectDeletionButton.vue

@ -1,41 +1,29 @@
<template> <template>
<v-dialog
v-model="dialog"
width="800px"
<base-modal
text="Delete"
:disabled="!isProjectSelected"
> >
<template v-slot:activator="{ on }">
<v-btn
class="mb-2 ml-2 text-capitalize"
outlined
:disabled="!isProjectSelected"
@click="dialog=true"
>
Delete
</v-btn>
<template v-slot="slotProps">
<project-deletion-form
:selected="selected"
@delete="handleDeleteProject(); slotProps.close()"
@close="slotProps.close"
/>
</template> </template>
<project-deletion-form
:selected="selected"
@delete="handleDeleteProject"
@close="dialog=false"
/>
</v-dialog>
</base-modal>
</template> </template>
<script> <script>
import { mapState, mapGetters } from 'vuex' import { mapState, mapGetters } from 'vuex'
import BaseModal from '@/components/molecules/BaseModal'
import ProjectDeletionForm from '@/components/organisms/ProjectDeletionForm' import ProjectDeletionForm from '@/components/organisms/ProjectDeletionForm'
export default { export default {
components: { components: {
BaseModal,
ProjectDeletionForm ProjectDeletionForm
}, },
data() {
return {
dialog: false
}
},
computed: { computed: {
...mapState('projects', ['selected']), ...mapState('projects', ['selected']),
...mapGetters('projects', ['isProjectSelected']) ...mapGetters('projects', ['isProjectSelected'])
@ -44,7 +32,6 @@ export default {
methods: { methods: {
handleDeleteProject() { handleDeleteProject() {
this.$store.dispatch('projects/deleteProject') this.$store.dispatch('projects/deleteProject')
this.dialog = false
} }
} }
} }

64
frontend/components/molecules/BaseModal.vue

@ -0,0 +1,64 @@
<template>
<v-dialog
v-model="dialog"
width="800px"
>
<template v-slot:activator="{ on }">
<v-btn
class="mb-2 text-capitalize"
:class="classObject"
:color="color"
:outlined="isOutlined"
:disabled="disabled"
@click="dialog=true"
>
{{ text }}
</v-btn>
</template>
<slot :close="close" />
</v-dialog>
</template>
<script>
export default {
props: {
text: {
type: String,
default: '',
required: true
},
disabled: {
type: Boolean,
default: false
},
isCreate: {
type: Boolean,
default: false
}
},
data() {
return {
dialog: false
}
},
computed: {
classObject() {
return this.isCreate ? [] : ['ml-2']
},
color() {
return this.isCreate ? 'primary' : ''
},
isOutlined() {
return !this.isCreate
}
},
methods: {
close() {
this.dialog = false
}
}
}
</script>
Loading…
Cancel
Save