Skip to content

Commit a0de666

Browse files
Merge pull request #2283 from frappe/develop
chore(release): dev to main
2 parents b49a618 + cfac39d commit a0de666

24 files changed

+197
-737
lines changed

desk/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"lodash": "^4.17.21",
2727
"lucide-static": "^0.276.0",
2828
"mime": "^3.0.0",
29-
"mitt": "^3.0.1",
3029
"pinia": "^2.0.33",
3130
"pluralize": "^8.0.0",
3231
"sanitize-html": "^2.10.0",

desk/src/components/EmptyMessage.vue

-9
This file was deleted.

desk/src/components/desk/global/NewContactDialog.vue

+27-22
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
>
1111
<span class="mb-2 block text-sm leading-4 text-gray-700">
1212
{{ field.label }}
13+
<span
14+
v-if="field.required"
15+
class="place-self-center text-red-500"
16+
>
17+
*
18+
</span>
1319
</span>
1420
<Input
1521
v-if="field.type === 'input'"
@@ -21,7 +27,6 @@
2127
v-else
2228
v-model="state[field.value]"
2329
:options="customerResource.data"
24-
:value="state[field.value]"
2530
@update:model-value="handleCustomerChange"
2631
/>
2732
<ErrorMessage :message="error[field.error]" />
@@ -76,7 +81,7 @@ const state = ref({
7681
firstName: "",
7782
lastName: "",
7883
phone: "",
79-
selectedCustomer: "",
84+
selectedCustomer: null,
8085
});
8186
8287
const error = ref({
@@ -92,6 +97,7 @@ interface FormField {
9297
value: string;
9398
error: string;
9499
type: string;
100+
required: boolean;
95101
action?: () => void;
96102
}
97103
@@ -101,34 +107,38 @@ const formFields: FormField[] = [
101107
value: "emailID",
102108
error: "emailValidationError",
103109
type: "input",
110+
required: true,
104111
action: () => validateEmailInput(state.value.emailID),
105112
},
106113
{
107114
label: "First Name",
108115
value: "firstName",
109116
error: "firstNameValidationError",
110117
type: "input",
118+
required: true,
111119
action: () => validateFirstName(state.value.firstName),
112120
},
113121
{
114122
label: "Last Name",
115123
value: "lastName",
116124
error: "lastNameValidationError",
117125
type: "input",
126+
required: false,
118127
},
119128
{
120129
label: "Phone",
121130
value: "phone",
122131
error: "phoneValidationError",
123132
type: "input",
133+
required: false,
124134
action: () => validatePhone(state.value.phone),
125135
},
126136
{
127137
label: "Customer",
128138
value: "selectedCustomer",
129139
error: "customerValidationError",
130140
type: "autocomplete",
131-
action: () => validateCustomer(state.value.selectedCustomer),
141+
required: false,
132142
},
133143
];
134144
@@ -165,7 +175,7 @@ const contactResource = createResource({
165175
firstName: "",
166176
lastName: "",
167177
phone: "",
168-
selectedCustomer: "",
178+
selectedCustomer: null,
169179
};
170180
createToast({
171181
title: "Contact Created Successfully ",
@@ -184,31 +194,34 @@ function createContact() {
184194
first_name: state.value.firstName,
185195
last_name: state.value.lastName,
186196
email_ids: [{ email_id: state.value.emailID, is_primary: true }],
187-
links: [
188-
{
189-
link_doctype: "HD Customer",
190-
link_name: state.value.selectedCustomer,
191-
},
192-
],
197+
links: [],
193198
phone_nos: [],
194199
};
195200
if (state.value.phone) {
196201
doc.phone_nos = [{ phone: state.value.phone }];
197202
}
203+
if (state.value.selectedCustomer) {
204+
doc.links.push({
205+
link_doctype: "HD Customer",
206+
link_name: state.value.selectedCustomer,
207+
});
208+
}
198209
199210
contactResource.submit({ doc });
200211
}
201212
202-
function handleCustomerChange(item: AutoCompleteItem) {
203-
if (!item) return;
204-
state.value.selectedCustomer = item.value;
213+
function handleCustomerChange(item: AutoCompleteItem | null) {
214+
if (!item || item.label === "No label") {
215+
state.value.selectedCustomer = null;
216+
} else {
217+
state.value.selectedCustomer = item.value;
218+
}
205219
}
206220
207221
function validateInputs() {
208222
let error = validateEmailInput(state.value.emailID);
209223
error += validateFirstName(state.value.firstName);
210224
error += validatePhone(state.value.phone);
211-
error += validateCustomer(state.value.selectedCustomer);
212225
return error;
213226
}
214227
@@ -243,14 +256,6 @@ function validatePhone(value: string) {
243256
return error.value.phoneValidationError;
244257
}
245258
246-
function validateCustomer(value: string) {
247-
error.value.customerValidationError = "";
248-
if (!value || value.trim() === "") {
249-
error.value.customerValidationError = "Customer should not be empty";
250-
}
251-
return error.value.customerValidationError;
252-
}
253-
254259
function existingContactEmails(contacts) {
255260
return contacts.map((contact) => contact.email_id);
256261
}

desk/src/components/desk/global/TimeDurationInput.vue

-126
This file was deleted.

desk/src/composables/formCustomisation.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import { Field } from "@/types";
22

3-
export function setupCustomizations(data, obj) {
3+
export async function setupCustomizations(doc, obj) {
4+
let data = doc?.data;
5+
if (!data) return;
46
if (!data._form_script) return [];
57
let actions = [];
68
let onChangeFieldMap = {};
79
if (Array.isArray(data._form_script)) {
8-
data._form_script.forEach((script) => {
9-
const parsed = parseScript(script, obj);
10+
for (const script of data._form_script) {
11+
const parsed = await parseScript(script, obj);
1012
actions = actions.concat(parsed.actions);
1113
if (parsed.onChange) {
1214
parseOnChangeFn(onChangeFieldMap, parsed.onChange);
1315
}
14-
});
16+
}
1517
} else {
16-
const parsed = parseScript(data._form_script, obj);
18+
const parsed = await parseScript(data._form_script, obj);
1719
actions = parsed.actions;
1820
if (parsed.onChange) {
1921
parseOnChangeFn(onChangeFieldMap, parsed.onChange);
@@ -34,9 +36,9 @@ function parseOnChangeFn(fieldMap: object, currentField: object) {
3436
}
3537
}
3638

37-
function parseScript(script, obj) {
39+
async function parseScript(script, obj) {
3840
const scriptFn = new Function(script + "\nreturn setupForm")();
39-
const formScript = scriptFn(obj);
41+
const formScript = await scriptFn(obj);
4042
return {
4143
actions: formScript?.actions || [],
4244
onChange: formScript?.onChange || null,

desk/src/emitter.ts

-3
This file was deleted.

0 commit comments

Comments
 (0)