fix loading show form page (#361)
Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
parent
e517cba88a
commit
2191f46214
|
|
@ -55,6 +55,26 @@ class FormController extends Controller
|
||||||
return FormResource::collection($forms);
|
return FormResource::collection($forms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function show($slug)
|
||||||
|
{
|
||||||
|
$form = Form::whereSlug($slug)->firstOrFail();
|
||||||
|
$this->authorize('view', $form);
|
||||||
|
|
||||||
|
// Add attributes for faster loading
|
||||||
|
$workspace = $form->workspace;
|
||||||
|
$form->extra = (object)[
|
||||||
|
'loadedWorkspace' => $workspace,
|
||||||
|
'workspaceIsPro' => $workspace->is_pro,
|
||||||
|
'userIsOwner' => true,
|
||||||
|
'cleanings' => $this->formCleaner
|
||||||
|
->processForm(request(), $form)
|
||||||
|
->simulateCleaning($workspace)
|
||||||
|
->getPerformedCleanings(),
|
||||||
|
];
|
||||||
|
|
||||||
|
return new FormResource($form);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all user forms, used for zapier
|
* Return all user forms, used for zapier
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,7 @@ useOpnSeoMeta({
|
||||||
title: 'Home'
|
title: 'Home'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
const formsStore = useFormsStore()
|
const formsStore = useFormsStore()
|
||||||
const workingFormStore = useWorkingFormStore()
|
const workingFormStore = useWorkingFormStore()
|
||||||
|
|
@ -195,7 +196,7 @@ onMounted(() => {
|
||||||
if (form.value) {
|
if (form.value) {
|
||||||
workingFormStore.set(form.value)
|
workingFormStore.set(form.value)
|
||||||
} else {
|
} else {
|
||||||
formsStore.loadAll(useWorkspacesStore().currentId)
|
formsStore.loadForm(route.params.slug)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {defineStore} from 'pinia'
|
||||||
import {useContentStore} from "~/composables/stores/useContentStore.js";
|
import {useContentStore} from "~/composables/stores/useContentStore.js";
|
||||||
|
|
||||||
export const formsEndpoint = '/open/workspaces/{workspaceId}/forms'
|
export const formsEndpoint = '/open/workspaces/{workspaceId}/forms'
|
||||||
|
export const singleFormEndpoint = '/open/forms/{slug}'
|
||||||
|
|
||||||
export const useFormsStore = defineStore('forms', () => {
|
export const useFormsStore = defineStore('forms', () => {
|
||||||
|
|
||||||
|
|
@ -33,6 +34,16 @@ export const useFormsStore = defineStore('forms', () => {
|
||||||
throw error
|
throw error
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
const loadForm = (slug) => {
|
||||||
|
contentStore.startLoading()
|
||||||
|
return opnFetch(singleFormEndpoint.replace('{slug}', slug))
|
||||||
|
.then(response => {
|
||||||
|
contentStore.save(response)
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
contentStore.stopLoading()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const load = (workspaceId, slug) => {
|
const load = (workspaceId, slug) => {
|
||||||
contentStore.startLoading()
|
contentStore.startLoading()
|
||||||
|
|
@ -76,6 +87,7 @@ export const useFormsStore = defineStore('forms', () => {
|
||||||
publicLoad,
|
publicLoad,
|
||||||
publicFetch,
|
publicFetch,
|
||||||
loadAll,
|
loadAll,
|
||||||
|
loadForm,
|
||||||
load,
|
load,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ Route::group(['middleware' => 'auth:api'], function () {
|
||||||
|
|
||||||
Route::prefix('open')->name('open.')->group(function () {
|
Route::prefix('open')->name('open.')->group(function () {
|
||||||
Route::get('/forms', [FormController::class, 'indexAll'])->name('forms.index-all');
|
Route::get('/forms', [FormController::class, 'indexAll'])->name('forms.index-all');
|
||||||
|
Route::get('/forms/{slug}', [FormController::class, 'show'])->name('forms.show');
|
||||||
|
|
||||||
Route::prefix('workspaces')->name('workspaces.')->group(function () {
|
Route::prefix('workspaces')->name('workspaces.')->group(function () {
|
||||||
Route::get('/', [WorkspaceController::class, 'index'])->name('index');
|
Route::get('/', [WorkspaceController::class, 'index'])->name('index');
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,19 @@ it('can fetch forms', function () {
|
||||||
->assertJsonPath('data.0.title', $form->title);
|
->assertJsonPath('data.0.title', $form->title);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can fetch a form', function () {
|
||||||
|
$user = $this->actingAsProUser();
|
||||||
|
$workspace = $this->createUserWorkspace($user);
|
||||||
|
$form = $this->createForm($user, $workspace);
|
||||||
|
|
||||||
|
$response = $this->getJson(route('open.forms.show', $form->slug))
|
||||||
|
->assertSuccessful()
|
||||||
|
->assertJson([
|
||||||
|
'id' => $form->id,
|
||||||
|
'title' => $form->title
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it('can update a form', function () {
|
it('can update a form', function () {
|
||||||
$user = $this->actingAsUser();
|
$user = $this->actingAsUser();
|
||||||
$workspace = $this->createUserWorkspace($user);
|
$workspace = $this->createUserWorkspace($user);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue