Skip to content

Commit e7d9817

Browse files
committed
modified the warning and success message.
1 parent 562f645 commit e7d9817

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

packages/Webkul/Admin/src/Http/Controllers/Contact/Persons/PersonController.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,23 @@ public function destroy(int $id): JsonResponse
167167
}
168168

169169
/**
170-
* Mass Delete the specified resources.
170+
* Mass destroy the specified resources from storage.
171171
*/
172172
public function massDestroy(MassDestroyRequest $request): JsonResponse
173173
{
174174
try {
175175
$persons = $this->personRepository->findWhereIn('id', $request->input('indices', []));
176176

177-
$hasBlocked = false;
177+
$deletedCount = 0;
178+
179+
$blockedCount = 0;
178180

179181
foreach ($persons as $person) {
180182
if (
181183
$person->leads
182184
&& $person->leads->count() > 0
183185
) {
184-
$hasBlocked = true;
186+
$blockedCount++;
185187

186188
continue;
187189
}
@@ -191,15 +193,34 @@ public function massDestroy(MassDestroyRequest $request): JsonResponse
191193
$this->personRepository->delete($person->id);
192194

193195
Event::dispatch('contact.person.delete.after', $person);
196+
197+
$deletedCount++;
194198
}
195199

196-
$message = trans('admin::app.contacts.persons.index.delete-success');
200+
$statusCode = 200;
201+
202+
switch (true) {
203+
case ($deletedCount > 0 && $blockedCount === 0):
204+
$message = trans('admin::app.contacts.persons.index.all-delete-success');
205+
break;
197206

198-
if ($hasBlocked) {
199-
$message .= ' '.trans('admin::app.contacts.persons.index.some-not-deleted-warning');
207+
case ($deletedCount > 0 && $blockedCount > 0):
208+
$message = trans('admin::app.contacts.persons.index.partial-delete-warning');
209+
break;
210+
211+
case ($deletedCount === 0 && $blockedCount > 0):
212+
$message = trans('admin::app.contacts.persons.index.none-delete-warning');
213+
$statusCode = 400;
214+
break;
215+
216+
default:
217+
$message = trans('admin::app.contacts.persons.index.no-selection');
218+
$statusCode = 400;
219+
break;
200220
}
201221

202-
return response()->json(['message' => $message]);
222+
return response()->json(['message' => $message], $statusCode);
223+
203224
} catch (Exception $exception) {
204225
return response()->json([
205226
'message' => trans('admin::app.contacts.persons.index.delete-failed'),

packages/Webkul/Admin/src/Resources/lang/en/app.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,11 @@
545545
'create-btn' => 'Create Person',
546546
'create-success' => 'Person created successfully.',
547547
'update-success' => 'Person updated successfully.',
548-
'delete-success' => 'Person deleted successfully.',
549-
'delete-failed' => 'Person can not be deleted.',
550-
'some-not-deleted-warning' => 'Some persons could not be deleted because they are linked to leads.',
548+
'all-delete-success' => 'All selected persons were deleted successfully.',
549+
'partial-delete-warning' => 'Some persons were deleted successfully. Others could not be deleted because they are linked to leads.',
550+
'none-delete-warning' => 'None of the selected persons could be deleted because they are linked to leads.',
551+
'no-selection' => 'No persons were selected for deletion.',
552+
'delete-failed' => 'Failed to delete selected persons.',
551553

552554
'datagrid' => [
553555
'contact-numbers' => 'Contact Numbers',

0 commit comments

Comments
 (0)