Beautiful Open-Source Form Builder
Form analytics now paid feature (#547)
Chirag Chhatrala89513e3b4ac7
diff --git a/api/app/Http/Controllers/Forms/FormStatsController.php b/api/app/Http/Controllers/Forms/FormStatsController.phpindex ecc1bb0e9..efb133ff1 100644--- a/api/app/Http/Controllers/Forms/FormStatsController.php+++ b/api/app/Http/Controllers/Forms/FormStatsController.php@@ -3,8 +3,8 @@namespace App\Http\Controllers\Forms;use App\Http\Controllers\Controller;-use App\Models\Forms\Form;use Carbon\CarbonPeriod;+use Illuminate\Http\Request;class FormStatsController extends Controller{@@ -13,10 +13,9 @@ class FormStatsController extends Controller$this->middleware('auth');}- public function getFormStats(string $workspaceId, string $formId)+ public function getFormStats(Request $request){- $form = Form::findOrFail($formId);-+ $form = $request->form; // Added by ProForm middleware$this->authorize('view', $form);$formStats = $form->statistics()->where('date', '>', now()->subDays(29)->startOfDay())->get();diff --git a/api/routes/api.php b/api/routes/api.phpindex 41b0962ea..c0376e2c6 100644--- a/api/routes/api.php+++ b/api/routes/api.php@@ -144,7 +144,9 @@ Route::group(['middleware' => 'auth:api'], function () {Route::put('/custom-domains', [WorkspaceController::class, 'saveCustomDomain'])->name('save-custom-domains');Route::delete('/', [WorkspaceController::class, 'delete'])->name('delete');- Route::get('form-stats/{formId}', [FormStatsController::class, 'getFormStats'])->name('form.stats');+ Route::middleware('pro-form')->group(function () {+ Route::get('form-stats/{formId}', [FormStatsController::class, 'getFormStats'])->name('form.stats');+ });});});diff --git a/api/tests/Feature/Forms/FormStatTest.php b/api/tests/Feature/Forms/FormStatTest.phpindex e21bd8106..9051937e7 100644--- a/api/tests/Feature/Forms/FormStatTest.php+++ b/api/tests/Feature/Forms/FormStatTest.php@@ -3,7 +3,7 @@use Illuminate\Support\Facades\Artisan;it('check formstat chart data', function () {- $user = $this->actingAsUser();+ $user = $this->actingAsProUser();$workspace = $this->createUserWorkspace($user);$form = $this->createForm($user, $workspace, []);diff --git a/client/components/open/forms/components/FormStats.vue b/client/components/open/forms/components/FormStats.vueindex 7a5e09625..445dcbf49 100644--- a/client/components/open/forms/components/FormStats.vue+++ b/client/components/open/forms/components/FormStats.vue@@ -3,7 +3,7 @@class="border border-nt-blue-light bg-blue-50 dark:bg-notion-dark-light rounded-md p-4 mb-5 w-full mx-auto mt-4 select-all"><div- v-if="false"+ v-if="!form.is_pro"class="relative"><div class="absolute inset-0 z-10">@@ -16,7 +16,10 @@analytics.</p><p class="mt-5 text-center">- <v-button :to="{ name: 'pricing' }">+ <v-button+ class="w-full"+ @click.prevent="subscriptionModalStore.openModal()"+ >Subscribe</v-button></p>@@ -76,6 +79,12 @@ export default {required: true,},},+ setup() {+ const subscriptionModalStore = useSubscriptionModalStore()+ return {+ subscriptionModalStore+ }+ },data() {return {isLoading: true,@@ -115,9 +124,7 @@ export default {},methods: {getChartData() {- if (!this.form) {- return null- }+ if (!this.form || !this.form.is_pro) { return null }this.isLoading = trueopnFetch("/open/workspaces/" +