Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom fields on adding new customer #1588

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion desk/src/components/UniInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<div class="space-y-1.5">
<span class="block text-sm text-gray-700">
{{ field.label }}
<span v-if="field.required" class="place-self-center text-red-500">
<span
v-if="field.required || field.reqd"
class="place-self-center text-red-500"
>
*
</span>
</span>
Expand Down
49 changes: 40 additions & 9 deletions desk/src/components/desk/global/NewCustomerDialog.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
<template>
<div>
<Dialog v-model="open" :options="{ title: 'Add New Customer', size: 'sm' }">
<FDialog
v-model="open"
:options="{ title: 'Add New Customer', size: 'sm' }"
>
<template #body-content>
<div class="space-y-4">
<div class="space-y-1">
<Input
<FInput
v-model="customer"
label="Customer Name"
type="text"
placeholder="Tesla Inc."
/>
</div>
<div class="space-y-1">
<Input
<FInput
v-model="domain"
label="Domain"
type="text"
placeholder="eg: tesla.com, mycompany.com"
/>
</div>
<div
v-for="field in visibleFields"
:key="field.fieldname"
class="space-y-1"
>
<UniInput
:field="field"
:value="customerFields[field.fieldname]"
@change="customerFields[field.fieldname] = $event.value"
/>
</div>
<div class="float-right flex space-x-2">
<Button
label="Add"
Expand All @@ -35,18 +49,27 @@
</div>
</div>
</template>
</Dialog>
</FDialog>
</div>
</template>

<script>
import { Input, Dialog, ErrorMessage } from "frappe-ui";
import { computed, ref, inject } from "vue";
import { Input as FInput, Dialog as FDialog, createResource } from "frappe-ui";
// To avoid vue/no-reserved-component-names
import { computed, reactive } from "vue";
import { UniInput } from "@/components";

const custom_fields = createResource({
url: "helpdesk.helpdesk.doctype.hd_customer.api.get_customer_fields",
auto: true,
});

export default {
name: "NewCustomerDialog",
components: {
Dialog,
Input,
FDialog,
FInput,
UniInput,
},
props: {
modelValue: {
Expand All @@ -72,13 +95,20 @@ export default {
return {
customer: "",
domain: "",
customerFields: reactive({}),
};
},
computed: {
visibleFields() {
return custom_fields.data || [];
},
},
methods: {
addCustomer() {
const inputParams = {
customer_name: this.customer,
domain: this.domain,
...this.customerFields,
};
this.$resources.newCustomer.submit({
doc: {
Expand All @@ -90,14 +120,15 @@ export default {
close() {
this.customer = "";
this.domain = "";
this.customerFields = reactive({});
this.$emit("close");
},
},
resources: {
newCustomer() {
return {
url: "frappe.client.insert",
onSuccess: (doc) => {
onSuccess: () => {
this.$router.push(`/customers`);
},
};
Expand Down
11 changes: 11 additions & 0 deletions helpdesk/helpdesk/doctype/hd_customer/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2023, Frappe Technologies and contributors
# For license information, please see license.txt

import frappe


@frappe.whitelist()
def get_customer_fields():
"""Return customer fields"""
meta = frappe.get_meta("HD Customer")
return meta.get("fields", {"reqd": 1, "fieldname": ["not in", ["customer", "domain"]]})