Skip to content

Commit a3ac81c

Browse files
Form analytics now paid feature
1 parent 79d3dd7 commit a3ac81c

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

api/app/Http/Controllers/Forms/FormStatsController.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace App\Http\Controllers\Forms;
44

55
use App\Http\Controllers\Controller;
6-
use App\Models\Forms\Form;
76
use Carbon\CarbonPeriod;
7+
use Illuminate\Http\Request;
88

99
class FormStatsController extends Controller
1010
{
@@ -13,10 +13,9 @@ public function __construct()
1313
$this->middleware('auth');
1414
}
1515

16-
public function getFormStats(string $workspaceId, string $formId)
16+
public function getFormStats(Request $request)
1717
{
18-
$form = Form::findOrFail($formId);
19-
18+
$form = $request->form; // Added by ProForm middleware
2019
$this->authorize('view', $form);
2120

2221
$formStats = $form->statistics()->where('date', '>', now()->subDays(29)->startOfDay())->get();

api/routes/api.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@
144144
Route::put('/custom-domains', [WorkspaceController::class, 'saveCustomDomain'])->name('save-custom-domains');
145145
Route::delete('/', [WorkspaceController::class, 'delete'])->name('delete');
146146

147-
Route::get('form-stats/{formId}', [FormStatsController::class, 'getFormStats'])->name('form.stats');
147+
Route::middleware('pro-form')->group(function () {
148+
Route::get('form-stats/{formId}', [FormStatsController::class, 'getFormStats'])->name('form.stats');
149+
});
148150
});
149151
});
150152

api/tests/Feature/Forms/FormStatTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use Illuminate\Support\Facades\Artisan;
44

55
it('check formstat chart data', function () {
6-
$user = $this->actingAsUser();
6+
$user = $this->actingAsProUser();
77
$workspace = $this->createUserWorkspace($user);
88
$form = $this->createForm($user, $workspace, []);
99

client/components/open/forms/components/FormStats.vue

+12-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
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"
44
>
55
<div
6-
v-if="false"
6+
v-if="!form.is_pro"
77
class="relative"
88
>
99
<div class="absolute inset-0 z-10">
@@ -16,7 +16,10 @@
1616
analytics.
1717
</p>
1818
<p class="mt-5 text-center">
19-
<v-button :to="{ name: 'pricing' }">
19+
<v-button
20+
class="w-full"
21+
@click.prevent="subscriptionModalStore.openModal()"
22+
>
2023
Subscribe
2124
</v-button>
2225
</p>
@@ -76,6 +79,12 @@ export default {
7679
required: true,
7780
},
7881
},
82+
setup() {
83+
const subscriptionModalStore = useSubscriptionModalStore()
84+
return {
85+
subscriptionModalStore
86+
}
87+
},
7988
data() {
8089
return {
8190
isLoading: true,
@@ -115,9 +124,7 @@ export default {
115124
},
116125
methods: {
117126
getChartData() {
118-
if (!this.form) {
119-
return null
120-
}
127+
if (!this.form || !this.form.is_pro) { return null }
121128
this.isLoading = true
122129
opnFetch(
123130
"/open/workspaces/" +

0 commit comments

Comments
 (0)