Skip to content

Commit

Permalink
Add donation amount config
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed May 14, 2024
1 parent c2908e7 commit b629150
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 96 deletions.
10 changes: 3 additions & 7 deletions app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Http\Filters\ProjectDatesFilter;
use App\Http\Filters\ProjectStatusFilter;
use App\Http\Filters\SearchFilter;
use App\Http\Requests\Project\DonateRequest;
use App\Http\Resources\Collections\ProjectCardCollection;
use App\Http\Resources\Project\ShowProjectResource;
use App\Http\Sorts\ProjectDonationsCountSort;
Expand Down Expand Up @@ -84,14 +85,9 @@ public function show(Project $project)
]);
}

public function donate(Project $project, Request $request)
public function donate(Project $project, DonateRequest $request)
{
$attributes = $request->validate([
'amount' => ['required', 'numeric', 'min:1'],
'terms' => ['required', 'accepted'],
'email' => ['required', 'email'],
'name' => ['required'],
]);
$attributes = $request->validated();

try {
[$lastName, $firstName] = explode(' ', $attributes['name']);
Expand Down
3 changes: 3 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,7 @@
// 'Example' => App\Facades\Example::class,
])->toArray(),

'min_donation' => env('MIN_DONATION', 10),
'max_donation' => env('MAX_DONATION', 10000),

];
4 changes: 4 additions & 0 deletions lang/ro/custom_validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,9 @@
'end' => [
'after' => 'Data de finalizare a proiectului trebuie să fie după data de început.',
],
'donate' => [
'min' => 'Suma minimă de donație este de :min RON.',
'max' => 'Suma maximă de donație este de :max RON.',
],
],
];
116 changes: 59 additions & 57 deletions resources/js/Components/modals/DonateModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
id="amount"
type="number"
v-model="guestForm.amount"
:error="guestForm.errors.amount"
:error="guestForm.errors.amount || errors?.amount"
/>

<!-- Amount -->
Expand All @@ -113,7 +113,7 @@
id="amount"
type="number"
v-model="authForm.amount"
:error="authForm.errors.amount"
:error="authForm.errors.amount || errors?.amount"
/>

<!-- Confirm -->
Expand Down Expand Up @@ -174,60 +174,62 @@
</template>

<script setup>
/** Import from vue */
import { ref } from 'vue';
import route from '@/Helpers/useRoute';
/** Import from inertia. */
import { Link, useForm, usePage } from '@inertiajs/vue3';
/** Import plugins. */
import { Dialog, DialogPanel, TransitionChild, TransitionRoot } from '@headlessui/vue';
import { XIcon } from '@heroicons/vue/outline';
/** Import components. */
import Input from '@/Components/form/Input.vue';
import Checkbox from '@/Components/form/Checkbox.vue';
import PrimaryButton from '@/Components/buttons/PrimaryButton.vue';
/** Component props. */
const props = defineProps({
triggerModalText: String,
triggerModalClasses: String,
data: [Object, Array, String, Number],
/** Import from vue */
import { computed, ref } from 'vue';
import route from '@/Helpers/useRoute';
/** Import from inertia. */
import { Link, useForm, usePage } from '@inertiajs/vue3';
/** Import plugins. */
import { Dialog, DialogPanel, TransitionChild, TransitionRoot } from '@headlessui/vue';
import { XIcon } from '@heroicons/vue/outline';
/** Import components. */
import Input from '@/Components/form/Input.vue';
import Checkbox from '@/Components/form/Checkbox.vue';
import PrimaryButton from '@/Components/buttons/PrimaryButton.vue';
/** Component props. */
const props = defineProps({
triggerModalText: String,
triggerModalClasses: String,
data: [Object, Array, String, Number],
errors: Object,
});
/** Local data. */
const open = ref(false);
const errors = computed(() => usePage().props.errors || null);
/** Initialize inertia from Object. */
const guestForm = useForm({
name: '',
email: '',
amount: '',
terms: false,
});
/** Initialize inertia from Object. */
const authForm = useForm({
amount: '',
});
/** Donate action */
const donate = () => {
/** Trigger donate post method. */
if (usePage().props.auth.user) {
guestForm.name = usePage().props.auth.user.name;
guestForm.email = usePage().props.auth.user.email;
guestForm.terms = true;
guestForm.amount = authForm.amount;
}
guestForm.post(route('projects.donate', props.data.slug), {
onSuccess: () => (open.value = false),
onError: (errors) => {
console.log('error', errors);
},
onFinish: () => guestForm.reset(),
});
/** Local data. */
const open = ref(false);
/** Initialize inertia from Object. */
const guestForm = useForm({
name: '',
email: '',
amount: '',
terms: false,
});
/** Initialize inertia from Object. */
const authForm = useForm({
amount: '',
});
/** Donate action */
const donate = () => {
/** Trigger donate post method. */
if (usePage().props.auth.user) {
guestForm.name = usePage().props.auth.user.name;
guestForm.email = usePage().props.auth.user.email;
guestForm.terms = true;
guestForm.amount = authForm.amount;
}
guestForm.post(route('projects.donate', props.data.slug), {
onSuccess: () => (open.value = false),
onError: (errors) => {
console.log('error', errors);
},
onFinish: () => guestForm.reset(),
});
};
};
</script>
64 changes: 32 additions & 32 deletions resources/js/Pages/Public/Website/Contact.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,41 @@
<h1 class="text-3xl font-bold text-primary-900">{{ $t('send_message') }}</h1>
<p class="text-sm font-medium text-gray-500">{{ $t('send_message_info') }}</p>

<form @submit.prevent="contact" class="pb-20 mt-2 space-y-6">
<!-- Name -->
<Input
class="w-full"
:label="$t('name_last_name')"
color="gray-700"
id="name"
type="text"
v-model="form.name"
:error="form.errors.name"
/>
<!-- <form @submit.prevent="contact" class="pb-20 mt-2 space-y-6">-->
<!-- &lt;!&ndash; Name &ndash;&gt;-->
<!-- <Input-->
<!-- class="w-full"-->
<!-- :label="$t('name_last_name')"-->
<!-- color="gray-700"-->
<!-- id="name"-->
<!-- type="text"-->
<!-- v-model="form.name"-->
<!-- :error="form.errors.name"-->
<!-- />-->

<!-- Email -->
<Input
class="w-full"
:label="$t('email')"
color="gray-700"
id="email"
type="email"
v-model="form.email"
:error="form.errors.email"
/>
<!-- &lt;!&ndash; Email &ndash;&gt;-->
<!-- <Input-->
<!-- class="w-full"-->
<!-- :label="$t('email')"-->
<!-- color="gray-700"-->
<!-- id="email"-->
<!-- type="email"-->
<!-- v-model="form.email"-->
<!-- :error="form.errors.email"-->
<!-- />-->

<!-- Mesaj -->
<Textarea
class="w-full"
:label="$t('message_label')"
id="text"
color="gray-700"
v-model="form.text"
:error="form.errors.text"
/>
<!-- &lt;!&ndash; Mesaj &ndash;&gt;-->
<!-- <Textarea-->
<!-- class="w-full"-->
<!-- :label="$t('message_label')"-->
<!-- id="text"-->
<!-- color="gray-700"-->
<!-- v-model="form.text"-->
<!-- :error="form.errors.text"-->
<!-- />-->

<PrimaryButton type="submit" :disabled="form.processing" :label="$t('send')" />
</form>
<!-- <PrimaryButton type="submit" :disabled="form.processing" :label="$t('send')" />-->
<!-- </form>-->
</div>

<div class="w-full space-y-4 sm:w-6/12">
Expand Down

0 comments on commit b629150

Please sign in to comment.