From c73fcd226bc9bee7108e21a257753df6501496f1 Mon Sep 17 00:00:00 2001 From: formsdev <136701234+formsdev@users.noreply.github.com> Date: Tue, 19 Mar 2024 19:47:23 +0530 Subject: [PATCH] extramenu improvement (#353) * extramenu improvement * fix test cases --- app/Http/Controllers/Forms/FormController.php | 22 +-- .../components/pages/forms/show/ExtraMenu.vue | 158 ++++++++---------- tests/Feature/Forms/FormTest.php | 7 +- 3 files changed, 83 insertions(+), 104 deletions(-) diff --git a/app/Http/Controllers/Forms/FormController.php b/app/Http/Controllers/Forms/FormController.php index 9c268c5f..52fec5dc 100644 --- a/app/Http/Controllers/Forms/FormController.php +++ b/app/Http/Controllers/Forms/FormController.php @@ -102,7 +102,7 @@ class FormController extends Controller ])); return $this->success([ - 'message' => $this->formCleaner->hasCleaned() ? 'Form successfully created, but the Pro features you used will be disabled when sharing your form:' : 'Form created.'.($form->visibility == 'draft' ? ' But other people won\'t be able to see the form since it\'s currently in draft mode' : ''), + 'message' => $this->formCleaner->hasCleaned() ? 'Form successfully created, but the Pro features you used will be disabled when sharing your form:' : 'Form created.' . ($form->visibility == 'draft' ? ' But other people won\'t be able to see the form since it\'s currently in draft mode' : ''), 'form' => (new FormResource($form))->setCleanings($this->formCleaner->getPerformedCleanings()), 'users_first_form' => $request->user()->forms()->count() == 1, ]); @@ -120,13 +120,13 @@ class FormController extends Controller // Set Removed Properties $formData['removed_properties'] = array_merge($form->removed_properties, collect($form->properties)->filter(function ($field) use ($formData) { - return ! Str::of($field['type'])->startsWith('nf-') && ! in_array($field['id'], collect($formData['properties'])->pluck('id')->toArray()); + return !Str::of($field['type'])->startsWith('nf-') && !in_array($field['id'], collect($formData['properties'])->pluck('id')->toArray()); })->toArray()); $form->update($formData); return $this->success([ - 'message' => $this->formCleaner->hasCleaned() ? 'Form successfully updated, but the Pro features you used will be disabled when sharing your form:' : 'Form updated.'.($form->visibility == 'draft' ? ' But other people won\'t be able to see the form since it\'s currently in draft mode' : ''), + 'message' => $this->formCleaner->hasCleaned() ? 'Form successfully updated, but the Pro features you used will be disabled when sharing your form:' : 'Form updated.' . ($form->visibility == 'draft' ? ' But other people won\'t be able to see the form since it\'s currently in draft mode' : ''), 'form' => (new FormResource($form))->setCleanings($this->formCleaner->getPerformedCleanings()), ]); } @@ -150,11 +150,11 @@ class FormController extends Controller // Create copy $formCopy = $form->replicate(); - $formCopy->title = 'Copy of '.$formCopy->title; + $formCopy->title = 'Copy of ' . $formCopy->title; $formCopy->save(); return $this->success([ - 'message' => 'Form successfully duplicated.', + 'message' => 'Form successfully duplicated. You are now editing the duplicated version of the form.', 'new_form' => new FormResource($formCopy), ]); } @@ -172,7 +172,7 @@ class FormController extends Controller $form->save(); return $this->success([ - 'message' => 'Form url successfully updated. Your new form url now is: '.$form->share_url.'.', + 'message' => 'Form url successfully updated. Your new form url now is: ' . $form->share_url . '.', 'form' => new FormResource($form), ]); } @@ -187,12 +187,12 @@ class FormController extends Controller $fileNameParser = StorageFileNameParser::parse($request->url); // Make sure we retrieve the file in tmp storage, move it to persistent - $fileName = PublicFormController::TMP_FILE_UPLOAD_PATH.'/'.$fileNameParser->uuid; - if (! Storage::exists($fileName)) { + $fileName = PublicFormController::TMP_FILE_UPLOAD_PATH . '/' . $fileNameParser->uuid; + if (!Storage::exists($fileName)) { // File not found, we skip return null; } - $newPath = self::ASSETS_UPLOAD_PATH.'/'.$fileNameParser->getMovedFileName(); + $newPath = self::ASSETS_UPLOAD_PATH . '/' . $fileNameParser->getMovedFileName(); Storage::move($fileName, $newPath); return $this->success([ @@ -209,8 +209,8 @@ class FormController extends Controller $form = Form::findOrFail($id); $this->authorize('view', $form); - $path = Str::of(PublicFormController::FILE_UPLOAD_PATH)->replace('?', $form->id).'/'.$fileName; - if (! Storage::exists($path)) { + $path = Str::of(PublicFormController::FILE_UPLOAD_PATH)->replace('?', $form->id) . '/' . $fileName; + if (!Storage::exists($path)) { return $this->error([ 'message' => 'File not found.', ]); diff --git a/client/components/pages/forms/show/ExtraMenu.vue b/client/components/pages/forms/show/ExtraMenu.vue index 9e6b10c3..2c5d0e96 100644 --- a/client/components/pages/forms/show/ExtraMenu.vue +++ b/client/components/pages/forms/show/ExtraMenu.vue @@ -4,145 +4,117 @@ - @@ -200,20 +174,26 @@ const copyLink = () => { const duplicateForm = () => { if (loadingDuplicate.value) return loadingDuplicate.value = true - opnFetch(formEndpoint.replace('{id}', props.form.id) + '/duplicate',{method: 'POST'}).then((data) => { + opnFetch(formEndpoint.replace('{id}', props.form.id) + '/duplicate', { method: 'POST' }).then((data) => { formsStore.save(data.new_form) router.push({ name: 'forms-slug-show', params: { slug: data.new_form.slug } }) - useAlert().success('Form was successfully duplicated.') + useAlert().success(data.message) + loadingDuplicate.value = false + }).catch((error) => { + useAlert().error(error.data.message) loadingDuplicate.value = false }) } const deleteForm = () => { if (loadingDelete.value) return loadingDelete.value = true - opnFetch(formEndpoint.replace('{id}', props.form.id),{method:'DELETE'}).then(() => { + opnFetch(formEndpoint.replace('{id}', props.form.id), { method: 'DELETE' }).then((data) => { formsStore.remove(props.form) router.push({ name: 'home' }) - useAlert().success('Form was deleted.') + useAlert().success(data.message) + loadingDelete.value = false + }).catch((error) => { + useAlert().error(error.data.message) loadingDelete.value = false }) } diff --git a/tests/Feature/Forms/FormTest.php b/tests/Feature/Forms/FormTest.php index 05af1482..2d8a7974 100644 --- a/tests/Feature/Forms/FormTest.php +++ b/tests/Feature/Forms/FormTest.php @@ -73,7 +73,7 @@ it('can regenerate a form url', function () { ->assertJson(function (AssertableJson $json) { return $json->where('type', 'success') ->where('form.slug', function ($value) { - if (! is_string($value) || (preg_match( + if (!is_string($value) || (preg_match( '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/', $value ) !== 1)) { @@ -94,7 +94,6 @@ it('can regenerate a form url', function () { }) ->etc(); }); - }); it('can duplicate a form', function () { @@ -106,14 +105,14 @@ it('can duplicate a form', function () { ->assertSuccessful() ->assertJson([ 'type' => 'success', - 'message' => 'Form successfully duplicated.', + 'message' => 'Form successfully duplicated. You are now editing the duplicated version of the form.', ]); expect($user->forms()->count())->toBe(2); expect($workspace->forms()->count())->toBe(2); $this->assertDatabaseHas('forms', [ 'id' => $response->json('new_form.id'), - 'title' => 'Copy of '.$form->title, + 'title' => 'Copy of ' . $form->title, 'description' => $form->description, ]); });