Skip to content

Commit b65afcd

Browse files
Merge pull request #2126 from krayin/qoutes-issue
fix: qoutes issues
2 parents 7bb2e53 + f77a056 commit b65afcd

File tree

7 files changed

+125
-88
lines changed

7 files changed

+125
-88
lines changed

packages/Webkul/Activity/src/Repositories/ActivityRepository.php

+18
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,30 @@ public function update(array $data, $id, $attribute = 'id')
8080
$activity->participants()->delete();
8181

8282
foreach ($data['participants']['users'] ?? [] as $userId) {
83+
/**
84+
* In some cases, the component exists in an HTML form, and traditional HTML does not send an empty array.
85+
* Therefore, we need to check for an empty string.
86+
* This scenario occurs only when all participants are removed.
87+
*/
88+
if (empty($userId)) {
89+
break;
90+
}
91+
8392
$activity->participants()->create([
8493
'user_id' => $userId,
8594
]);
8695
}
8796

8897
foreach ($data['participants']['persons'] ?? [] as $personId) {
98+
/**
99+
* In some cases, the component exists in an HTML form, and traditional HTML does not send an empty array.
100+
* Therefore, we need to check for an empty string.
101+
* This scenario occurs only when all participants are removed.
102+
*/
103+
if (empty($personId)) {
104+
break;
105+
}
106+
89107
$activity->participants()->create([
90108
'person_id' => $personId,
91109
]);

packages/Webkul/Admin/src/Http/Controllers/Activity/ActivityController.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,15 @@ public function update($id): RedirectResponse|JsonResponse
142142
{
143143
Event::dispatch('activity.update.before', $id);
144144

145-
$activity = $this->activityRepository->update(request()->all(), $id);
145+
$data = request()->all();
146+
147+
$activity = $this->activityRepository->update($data, $id);
148+
149+
$activity->leads()->sync(
150+
! empty($data['lead_id'])
151+
? [$data['lead_id']]
152+
: []
153+
);
146154

147155
Event::dispatch('activity.update.after', $activity);
148156

packages/Webkul/Admin/src/Resources/views/activities/edit.blade.php

+28-20
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class="primary-button"
3939
>
4040
@lang('admin::app.activities.edit.save-btn')
4141
</button>
42-
42+
4343
{!! view_render_event('admin.activities.edit.save_button.after') !!}
4444
</div>
4545
</div>
@@ -54,7 +54,7 @@ class="primary-button"
5454

5555
<!-- Schedule Date -->
5656
<x-admin::form.control-group>
57-
<div class="flex gap-2">
57+
<div class="flex gap-2">
5858
<div class="w-full">
5959
<x-admin::form.control-group.label class="required">
6060
@lang('admin::app.activities.edit.schedule_from')
@@ -101,7 +101,7 @@ class="flex w-full rounded-md border px-3 py-2 text-sm text-gray-600 transition-
101101
:label="trans('admin::app.activities.edit.comment')"
102102
:placeholder="trans('admin::app.activities.edit.comment')"
103103
/>
104-
104+
105105
<x-admin::form.control-group.error control-name="comment" />
106106
</x-admin::form.control-group>
107107

@@ -113,8 +113,8 @@ class="flex w-full rounded-md border px-3 py-2 text-sm text-gray-600 transition-
113113

114114
<!-- Participants Multi lookup Vue Component -->
115115
<v-multi-lookup-component>
116-
<div
117-
class="relative rounded border border-gray-200 px-2 py-1 hover:border-gray-400 focus:border-gray-400 dark:border-gray-800 dark:hover:border-gray-400 dark:focus:border-gray-400"
116+
<div
117+
class="relative rounded border border-gray-200 px-2 py-1 hover:border-gray-400 focus:border-gray-400 dark:border-gray-800 dark:hover:border-gray-400 dark:focus:border-gray-400"
118118
role="button"
119119
>
120120
<ul class="flex flex-wrap items-center gap-1">
@@ -176,7 +176,7 @@ class="w-full px-1 py-1 dark:bg-gray-900 dark:text-gray-300"
176176
<x-admin::form.control-group.label class="required">
177177
@lang('admin::app.activities.edit.title')
178178
</x-admin::form.control-group.label>
179-
179+
180180
<x-admin::form.control-group.control
181181
type="text"
182182
name="title"
@@ -189,13 +189,13 @@ class="w-full px-1 py-1 dark:bg-gray-900 dark:text-gray-300"
189189

190190
<x-admin::form.control-group.error control-name="title" />
191191
</x-admin::form.control-group>
192-
192+
193193
<!-- Edit Type -->
194194
<x-admin::form.control-group>
195195
<x-admin::form.control-group.label class="required">
196196
@lang('admin::app.activities.edit.type')
197197
</x-admin::form.control-group.label>
198-
198+
199199
<x-admin::form.control-group.control
200200
type="select"
201201
name="type"
@@ -208,16 +208,16 @@ class="w-full px-1 py-1 dark:bg-gray-900 dark:text-gray-300"
208208
<option value="call">
209209
@lang('admin::app.activities.edit.call')
210210
</option>
211-
211+
212212
<option value="meeting">
213213
@lang('admin::app.activities.edit.meeting')
214214
</option>
215-
215+
216216
<option value="lunch">
217217
@lang('admin::app.activities.edit.lunch')
218218
</option>
219219
</x-admin::form.control-group.control>
220-
220+
221221
<x-admin::form.control-group.error control-name="type" />
222222
</x-admin::form.control-group>
223223

@@ -250,7 +250,7 @@ class="w-full px-1 py-1 dark:bg-gray-900 dark:text-gray-300"
250250
{!! view_render_event('admin.activities.edit.form.after') !!}
251251

252252
@pushOnce('scripts')
253-
<script
253+
<script
254254
type="text/x-template"
255255
id="v-multi-lookup-component-template"
256256
>
@@ -260,6 +260,14 @@ class="w-full px-1 py-1 dark:bg-gray-900 dark:text-gray-300"
260260
<ul class="flex flex-wrap items-center gap-1">
261261
<!-- Added Participants -->
262262
<template v-for="userType in ['users', 'persons']">
263+
<template v-if="! addedParticipants[userType].length">
264+
<input
265+
type="hidden"
266+
:name="`participants[${userType}][]`"
267+
value=""
268+
/>
269+
</template>
270+
263271
<li
264272
class="flex items-center gap-1 rounded-md bg-slate-100 pl-2 dark:bg-slate-950 dark:text-gray-300"
265273
v-for="(user, index) in addedParticipants[userType]"
@@ -360,27 +368,27 @@ class="cursor-pointer rounded-sm px-3 py-2 text-sm text-gray-800 hover:bg-gray-1
360368
return {
361369
isSearching: {
362370
users: false,
363-
371+
364372
persons: false,
365373
},
366374
367375
searchTerm: '',
368376
369377
addedParticipants: {
370378
users: [],
371-
379+
372380
persons: [],
373381
},
374382
375383
searchedParticipants: {
376384
users: [],
377-
385+
378386
persons: [],
379387
},
380388
381389
searchEnpoints: {
382390
users: "{{ route('admin.settings.users.search') }}",
383-
391+
384392
persons: "{{ route('admin.contacts.persons.search') }}",
385393
},
386394
};
@@ -389,7 +397,7 @@ class="cursor-pointer rounded-sm px-3 py-2 text-sm text-gray-800 hover:bg-gray-1
389397
watch: {
390398
searchTerm(newVal, oldVal) {
391399
this.search('users');
392-
400+
393401
this.search('persons');
394402
},
395403
},
@@ -423,7 +431,7 @@ class="cursor-pointer rounded-sm px-3 py-2 text-sm text-gray-800 hover:bg-gray-1
423431
}
424432
})
425433
.then ((response) => {
426-
this.addedParticipants[userType].forEach(addedParticipant =>
434+
this.addedParticipants[userType].forEach(addedParticipant =>
427435
response.data.data = response.data.data.filter(participant => participant.id !== addedParticipant.id)
428436
);
429437
@@ -443,13 +451,13 @@ class="cursor-pointer rounded-sm px-3 py-2 text-sm text-gray-800 hover:bg-gray-1
443451
444452
this.searchedParticipants = {
445453
users: [],
446-
454+
447455
persons: [],
448456
};
449457
},
450458
451459
remove(userType, participant) {
452-
this.addedParticipants[userType] = this.addedParticipants[userType].filter(addedParticipant =>
460+
this.addedParticipants[userType] = this.addedParticipants[userType].filter(addedParticipant =>
453461
addedParticipant.id !== participant.id
454462
);
455463
},

packages/Webkul/Admin/src/Resources/views/components/attributes/edit/lookup.blade.php

+19-35
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,13 @@ class="text-2xl text-gray-600"
7676
</div>
7777
7878
<!-- Hidden Input Entity Value -->
79-
<template v-if="attribute['code'].includes('organization_id') && ! selectedItem.id">
80-
<input
81-
type="hidden"
82-
:name="attribute['code'].replace('organization_id', 'organization_name')"
83-
v-model="selectedItem.name"
84-
/>
85-
</template>
86-
87-
<template v-else>
88-
<input
89-
type="hidden"
90-
:name="attribute['code']"
91-
v-model="selectedItem.id"
92-
/>
93-
</template>
79+
<x-admin::form.control-group.control
80+
type="hidden"
81+
::name="attribute['code']"
82+
v-model="selectedItem.id"
83+
::rules="validations"
84+
::label="attribute['name']"
85+
/>
9486
9587
<!-- Popup Box -->
9688
<div
@@ -175,6 +167,8 @@ class="cursor-pointer border-t border-gray-800 px-4 py-2 text-gray-500 hover:bg-
175167
176168
searchRoute: `{{ route('admin.settings.attributes.lookup') }}/${this.attribute.lookup_type}`,
177169
170+
lookupEntityRoute: `{{ route('admin.settings.attributes.lookup_entity') }}/${this.attribute.lookup_type}`,
171+
178172
isSearching: false,
179173
};
180174
},
@@ -191,19 +185,6 @@ class="cursor-pointer border-t border-gray-800 px-4 py-2 text-gray-500 hover:bg-
191185
searchTerm(newVal, oldVal) {
192186
this.search();
193187
},
194-
195-
value(newVal, oldVal) {
196-
if (newVal === undefined) {
197-
this.selectedItem = {
198-
id: '',
199-
name: ''
200-
};
201-
}
202-
203-
if (newVal) {
204-
this.getLookUpEntity();
205-
}
206-
},
207188
},
208189
209190
computed: {
@@ -256,13 +237,16 @@ class="cursor-pointer border-t border-gray-800 px-4 py-2 text-gray-500 hover:bg-
256237
},
257238
258239
getLookUpEntity() {
259-
this.$axios.get(this.searchRoute, {
260-
params: { query: this.value?.name ?? ""}
240+
this.$axios.get(this.lookupEntityRoute, {
241+
params: { query: this.value?.id ?? ""}
261242
})
262243
.then (response => {
263-
const [result] = response.data;
264-
265-
this.selectedItem = result;
244+
this.selectedItem = Object.keys(response.data).length
245+
? response.data
246+
: {
247+
id: '',
248+
name: ''
249+
};
266250
})
267251
.catch (error => {});
268252
},
@@ -274,7 +258,7 @@ class="cursor-pointer border-t border-gray-800 px-4 py-2 text-gray-500 hover:bg-
274258
275259
this.searchTerm = '';
276260
277-
this.$emit('lookup-added', result);
261+
this.$emit('lookup-added', this.selectedItem);
278262
},
279263
280264
handleFocusOut(e) {
@@ -294,7 +278,7 @@ class="cursor-pointer border-t border-gray-800 px-4 py-2 text-gray-500 hover:bg-
294278
name: ''
295279
};
296280
297-
this.$emit('lookup-removed');
281+
this.$emit('lookup-removed', this.selectedItem);
298282
},
299283
},
300284
});

0 commit comments

Comments
 (0)