Skip to content

Commit

Permalink
refactor: moved assignto into a separate component
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik committed Jan 3, 2025
1 parent df824be commit bc192d1
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 70 deletions.
2 changes: 1 addition & 1 deletion crm/fcrm/doctype/crm_deal/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def get_deal(name):

deal["fields_meta"] = get_fields_meta("CRM Deal")
deal["_form_script"] = get_form_script("CRM Deal")
deal["_assign"] = get_assigned_users("CRM Deal", deal.name, deal.owner)
deal["_assign"] = get_assigned_users("CRM Deal", deal.name)
return deal


Expand Down
2 changes: 1 addition & 1 deletion crm/fcrm/doctype/crm_lead/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ def get_lead(name):

lead["fields_meta"] = get_fields_meta("CRM Lead")
lead["_form_script"] = get_form_script("CRM Lead")
lead["_assign"] = get_assigned_users("CRM Lead", lead.name, lead.owner)
lead["_assign"] = get_assigned_users("CRM Lead", lead.name)
return lead
31 changes: 31 additions & 0 deletions frontend/src/components/AssignTo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template>
<component
v-if="assignees?.length"
:is="assignees?.length == 1 ? 'Button' : 'div'"
>
<MultipleAvatar :avatars="assignees" @click="showAssignmentModal = true" />
</component>
<Button v-else @click="showAssignmentModal = true">
{{ __('Assign to') }}
</Button>
<AssignmentModal
v-if="showAssignmentModal"
v-model="showAssignmentModal"
v-model:assignees="assignees"
:doctype="doctype"
:doc="data"
/>
</template>
<script setup>
import MultipleAvatar from '@/components/MultipleAvatar.vue'
import AssignmentModal from '@/components/Modals/AssignmentModal.vue'
import { ref } from 'vue'
const props = defineProps({
data: Object,
doctype: String,
})
const showAssignmentModal = ref(false)
const assignees = defineModel()
</script>
4 changes: 0 additions & 4 deletions frontend/src/components/Modals/AssignmentModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ const addValue = (value) => {
}
function updateAssignees() {
if (assignees.value.length === 0) {
error.value = 'Please select at least one assignee'
return
}
const removedAssignees = oldAssignees.value
.filter(
(assignee) => !assignees.value.find((a) => a.name === assignee.name),
Expand Down
22 changes: 6 additions & 16 deletions frontend/src/pages/Deal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
</template>
<template #right-header>
<CustomActions v-if="customActions" :actions="customActions" />
<component :is="deal.data._assignedTo?.length == 1 ? 'Button' : 'div'">
<MultipleAvatar
:avatars="deal.data._assignedTo"
@click="showAssignmentModal = true"
/>
</component>
<AssignTo
v-model="deal.data._assignedTo"
:data="deal.data"
doctype="CRM Deal"
/>
<Dropdown :options="statusOptions('deal', updateField, customStatuses)">
<template #default="{ open }">
<Button
Expand Down Expand Up @@ -237,13 +236,6 @@
afterInsert: (doc) => addContact(doc.name),
}"
/>
<AssignmentModal
v-if="showAssignmentModal"
v-model="showAssignmentModal"
v-model:assignees="deal.data._assignedTo"
:doc="deal.data"
doctype="CRM Deal"
/>
<FilesUploader
v-if="deal.data?.name"
v-model="showFilesUploader"
Expand Down Expand Up @@ -278,9 +270,8 @@ import AttachmentIcon from '@/components/Icons/AttachmentIcon.vue'
import LayoutHeader from '@/components/LayoutHeader.vue'
import Activities from '@/components/Activities/Activities.vue'
import OrganizationModal from '@/components/Modals/OrganizationModal.vue'
import AssignmentModal from '@/components/Modals/AssignmentModal.vue'
import AssignTo from '@/components/AssignTo.vue'
import FilesUploader from '@/components/FilesUploader/FilesUploader.vue'
import MultipleAvatar from '@/components/MultipleAvatar.vue'
import ContactModal from '@/components/Modals/ContactModal.vue'
import Section from '@/components/Section.vue'
import SidePanelLayout from '@/components/SidePanelLayout.vue'
Expand Down Expand Up @@ -390,7 +381,6 @@ onBeforeUnmount(() => {
const reload = ref(false)
const showOrganizationModal = ref(false)
const showAssignmentModal = ref(false)
const showFilesUploader = ref(false)
const _organization = ref({})
Expand Down
22 changes: 6 additions & 16 deletions frontend/src/pages/Lead.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
</template>
<template #right-header>
<CustomActions v-if="customActions" :actions="customActions" />
<component :is="lead.data._assignedTo?.length == 1 ? 'Button' : 'div'">
<MultipleAvatar
:avatars="lead.data._assignedTo"
@click="showAssignmentModal = true"
/>
</component>
<AssignTo
v-model="lead.data._assignedTo"
:data="lead.data"
doctype="CRM Lead"
/>
<Dropdown :options="statusOptions('lead', updateField, customStatuses)">
<template #default="{ open }">
<Button
Expand Down Expand Up @@ -180,13 +179,6 @@
</div>
</Resizer>
</div>
<AssignmentModal
v-if="showAssignmentModal"
v-model="showAssignmentModal"
v-model:assignees="lead.data._assignedTo"
:doc="lead.data"
doctype="CRM Lead"
/>
<Dialog
v-model="showConvertToDealModal"
:options="{
Expand Down Expand Up @@ -286,9 +278,8 @@ import ContactsIcon from '@/components/Icons/ContactsIcon.vue'
import AttachmentIcon from '@/components/Icons/AttachmentIcon.vue'
import LayoutHeader from '@/components/LayoutHeader.vue'
import Activities from '@/components/Activities/Activities.vue'
import AssignmentModal from '@/components/Modals/AssignmentModal.vue'
import AssignTo from '@/components/AssignTo.vue'
import FilesUploader from '@/components/FilesUploader/FilesUploader.vue'
import MultipleAvatar from '@/components/MultipleAvatar.vue'
import Link from '@/components/Controls/Link.vue'
import SidePanelLayout from '@/components/SidePanelLayout.vue'
import SLASection from '@/components/SLASection.vue'
Expand Down Expand Up @@ -373,7 +364,6 @@ onMounted(() => {
})
const reload = ref(false)
const showAssignmentModal = ref(false)
const showFilesUploader = ref(false)
function updateLead(fieldname, value, callback) {
Expand Down
22 changes: 6 additions & 16 deletions frontend/src/pages/MobileDeal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@
v-if="deal.data"
class="flex h-12 items-center justify-between gap-2 border-b px-3 py-2.5"
>
<component :is="deal.data._assignedTo?.length == 1 ? 'Button' : 'div'">
<MultipleAvatar
:avatars="deal.data._assignedTo"
@click="showAssignmentModal = true"
/>
</component>
<AssignTo
v-model="deal.data._assignedTo"
:data="deal.data"
doctype="CRM Deal"
/>
<div class="flex items-center gap-2">
<CustomActions v-if="customActions" :actions="customActions" />
</div>
Expand Down Expand Up @@ -236,13 +235,6 @@
afterInsert: (doc) => addContact(doc.name),
}"
/>
<AssignmentModal
v-if="showAssignmentModal"
v-model="showAssignmentModal"
v-model:assignees="deal.data._assignedTo"
:doc="deal.data"
doctype="CRM Deal"
/>
</template>
<script setup>
import Icon from '@/components/Icon.vue'
Expand All @@ -263,8 +255,7 @@ import SuccessIcon from '@/components/Icons/SuccessIcon.vue'
import LayoutHeader from '@/components/LayoutHeader.vue'
import Activities from '@/components/Activities/Activities.vue'
import OrganizationModal from '@/components/Modals/OrganizationModal.vue'
import AssignmentModal from '@/components/Modals/AssignmentModal.vue'
import MultipleAvatar from '@/components/MultipleAvatar.vue'
import AssignTo from '@/components/AssignTo.vue'
import ContactModal from '@/components/Modals/ContactModal.vue'
import Link from '@/components/Controls/Link.vue'
import Section from '@/components/Section.vue'
Expand Down Expand Up @@ -356,7 +347,6 @@ onMounted(() => {
const reload = ref(false)
const showOrganizationModal = ref(false)
const showAssignmentModal = ref(false)
const _organization = ref({})
function updateDeal(fieldname, value, callback) {
Expand Down
22 changes: 6 additions & 16 deletions frontend/src/pages/MobileLead.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@
v-if="lead.data"
class="flex h-12 items-center justify-between gap-2 border-b px-3 py-2.5"
>
<component :is="lead.data._assignedTo?.length == 1 ? 'Button' : 'div'">
<MultipleAvatar
:avatars="lead.data._assignedTo"
@click="showAssignmentModal = true"
/>
</component>
<AssignTo
v-model="lead.data._assignedTo"
:data="lead.data"
doctype="CRM Lead"
/>
<div class="flex items-center gap-2">
<CustomActions v-if="customActions" :actions="customActions" />
<Button
Expand Down Expand Up @@ -96,13 +95,6 @@
/>
</Tabs>
</div>
<AssignmentModal
v-if="showAssignmentModal"
v-model="showAssignmentModal"
v-model:assignees="lead.data._assignedTo"
:doc="lead.data"
doctype="CRM Lead"
/>
<Dialog
v-model="showConvertToDealModal"
:options="{
Expand Down Expand Up @@ -186,8 +178,7 @@ import OrganizationsIcon from '@/components/Icons/OrganizationsIcon.vue'
import ContactsIcon from '@/components/Icons/ContactsIcon.vue'
import LayoutHeader from '@/components/LayoutHeader.vue'
import Activities from '@/components/Activities/Activities.vue'
import AssignmentModal from '@/components/Modals/AssignmentModal.vue'
import MultipleAvatar from '@/components/MultipleAvatar.vue'
import AssignTo from '@/components/AssignTo.vue'
import Link from '@/components/Controls/Link.vue'
import Section from '@/components/Section.vue'
import SidePanelLayout from '@/components/SidePanelLayout.vue'
Expand Down Expand Up @@ -266,7 +257,6 @@ onMounted(() => {
})
const reload = ref(false)
const showAssignmentModal = ref(false)
function updateLead(fieldname, value, callback) {
value = Array.isArray(fieldname) ? '' : value
Expand Down

0 comments on commit bc192d1

Please sign in to comment.