Skip to content

Commit

Permalink
add submission per user
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinecraft committed Dec 26, 2023
1 parent 6c0ada7 commit 1bc0b34
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
5 changes: 4 additions & 1 deletion app/Http/Controllers/Admin/CustomFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ public function index()
'status',
'can_create_submission',
'min_role_weight_to_view_submission',
'max_submission_per_user',
'is_notify_staff_on_submission',
'created_at',
'created_by',
AllowedFilter::custom('q', new FilterMultipleFields(['id', 'title', 'slug', 'description', 'min_role_weight_to_view_submission'])),
])
->allowedSorts(['id', 'title', 'slug', 'status', 'can_create_submission', 'min_role_weight_to_view_submission', 'is_notify_staff_on_submission', 'created_at'])
->allowedSorts(['id', 'title', 'slug', 'status', 'max_submission_per_user', 'can_create_submission', 'min_role_weight_to_view_submission', 'is_notify_staff_on_submission', 'created_at'])
->defaultSort('-id')
->paginate($perPage)
->withQueryString();
Expand All @@ -61,6 +62,7 @@ public function store(CreateCustomFormRequest $request)
'description' => $request->description,
'status' => $request->status,
'can_create_submission' => $request->can_create_submission,
'max_submission_per_user' => $request->max_submission_per_user,
'min_role_weight_to_view_submission' => $request->min_role_weight_to_view_submission,
'is_notify_staff_on_submission' => $request->is_notify_staff_on_submission,
'fields' => $request->fields,
Expand Down Expand Up @@ -89,6 +91,7 @@ public function update(UpdateCustomFormRequest $request, CustomForm $customForm)
$customForm->description = $request->description;
$customForm->status = $request->status;
$customForm->can_create_submission = $request->can_create_submission;
$customForm->max_submission_per_user = $request->max_submission_per_user;
$customForm->min_role_weight_to_view_submission = $request->min_role_weight_to_view_submission;
$customForm->is_notify_staff_on_submission = $request->is_notify_staff_on_submission;
$customForm->fields = $request->fields;
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/CreateCustomFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function rules(): array
'status' => ['required', new EnumValue(CustomFormStatus::class)],
'can_create_submission' => 'required|string|in:anyone,auth,staff',
'min_role_weight_to_view_submission' => 'nullable|integer',
'max_submission_per_user' => 'nullable|integer|min:1',
'is_notify_staff_on_submission' => 'required|boolean',
'fields' => 'required|array',
'fields.*.type' => 'required|string|in:'.implode(',', $inputTypes),
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/UpdateCustomFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function rules(): array
'status' => ['required', new EnumValue(CustomFormStatus::class)],
'can_create_submission' => 'required|string|in:anyone,auth,staff',
'min_role_weight_to_view_submission' => 'nullable|integer',
'max_submission_per_user' => 'nullable|integer|min:1',
'is_notify_staff_on_submission' => 'required|boolean',
'fields' => 'required|array',
'fields.*.type' => 'required|string|in:'.implode(',', $inputTypes),
Expand Down
23 changes: 22 additions & 1 deletion resources/js/Pages/Admin/CustomForm/CreateCustomForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
/>
</div>

<div class="col-span-6 sm:col-span-6">
<div class="col-span-6 sm:col-span-3">
<x-select
id="can_create_submission"
v-model="form.can_create_submission
Expand All @@ -102,6 +102,21 @@
/>
</div>

<div class="col-span-6 sm:col-span-3">
<x-input
v-if="form.can_create_submission !== 'anyone'"
id="max_submission_per_user"
v-model="form.max_submission_per_user"
:label="__('Max Submission Per User')
"
:help="__('Leave empty to allow unlimited submission per user.')"
:error="form.errors.max_submission_per_user"
type="number"
name="max_submission_per_user"
help-error-flex="flex-row"
/>
</div>

<div class="col-span-6 sm:col-span-3">
<x-input
id="min_role_weight_to_view_submission"
Expand Down Expand Up @@ -441,6 +456,7 @@ const form = useForm({
status: 'draft',
description: '',
can_create_submission: 'anyone',
max_submission_per_user: null,
min_role_weight_to_view_submission: null,
is_notify_staff_on_submission: true,
fields: [
Expand Down Expand Up @@ -472,6 +488,11 @@ const createCustomForm = () => {
form.fields.map(item => {
item.name = item.label.toLowerCase().replace(/ /g, '_');
});
if (form.can_create_submission === 'anyone') {
form.max_submission_per_user = null;
}
form.post(route('admin.custom-form.store'), {});
};
Expand Down
23 changes: 22 additions & 1 deletion resources/js/Pages/Admin/CustomForm/EditCustomForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
/>
</div>

<div class="col-span-6 sm:col-span-6">
<div class="col-span-6 sm:col-span-3">
<x-select
id="can_create_submission"
v-model="form.can_create_submission
Expand All @@ -102,6 +102,21 @@
/>
</div>

<div class="col-span-6 sm:col-span-3">
<x-input
v-if="form.can_create_submission !== 'anyone'"
id="max_submission_per_user"
v-model="form.max_submission_per_user"
:label="__('Max Submission Per User')
"
:help="__('Leave empty to allow unlimited submission per user.')"
:error="form.errors.max_submission_per_user"
type="number"
name="max_submission_per_user"
help-error-flex="flex-row"
/>
</div>

<div class="col-span-6 sm:col-span-3">
<x-input
id="min_role_weight_to_view_submission"
Expand Down Expand Up @@ -445,6 +460,7 @@ const form = useForm({
status: props.customForm.status.value,
description: props.customForm.description,
can_create_submission: props.customForm.can_create_submission,
max_submission_per_user: props.customForm.max_submission_per_user,
min_role_weight_to_view_submission: props.customForm.min_role_weight_to_view_submission,
is_notify_staff_on_submission: props.customForm.is_notify_staff_on_submission,
fields: props.customForm.fields,
Expand All @@ -458,6 +474,11 @@ const submitForm = () => {
form.fields.map(item => {
item.name = item.label.toLowerCase().replace(/ /g, '_');
});
if (form.can_create_submission === 'anyone') {
form.max_submission_per_user = null;
}
form.post(route('admin.custom-form.update', props.customForm.id), {});
};
Expand Down

0 comments on commit 1bc0b34

Please sign in to comment.