Skip to content

Commit

Permalink
fix volunteer applications
Browse files Browse the repository at this point in the history
  • Loading branch information
IrynaKolh committed Jan 15, 2025
1 parent e6608aa commit 6470ca0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
6 changes: 6 additions & 0 deletions back-end/app/controllers/volunteer_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ class VolunteerApplicationsController < ApplicationController
def index
# Filtering
query_object = VolunteerApplication.includes(request: :org_service, volunteer: {})

if params[:volunteer_id]
query_object = query_object.where(volunteer_id: params[:volunteer_id])
else
render json: { error: 'volunteer_id is required' }, status: :unprocessable_entity and return
end

if params[:organization_id]
query_object = query_object.joins(request: :org_service)
Expand Down
14 changes: 12 additions & 2 deletions front-end/src/components/pages/volunteer/MyApplications.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
import { getMyApplications } from '../../../utils/apiReqests';
import { useGlobal } from '../.././../context/useGlobal.jsx';
import { useNavigate } from 'react-router-dom';
import { PencilIcon, TrashIcon } from '@heroicons/react/24/solid';

function MyApplications() {
const [myApplication, setMyApplication] = useState(null);
Expand All @@ -12,8 +13,8 @@ function MyApplications() {
const fetchData = async () => {
try {
const response = await getMyApplications(volunteer.id);
console.log('Fetched applications:', response);
setMyApplication(response);
console.log('Fetched applications:', response.applications);
setMyApplication(response.applications);
} catch (error) {
console.error('Error fetching applications:', error);
}
Expand Down Expand Up @@ -45,6 +46,7 @@ function MyApplications() {
<th className="border border-gray-300 px-4 py-2">Status</th>
<th className="border border-gray-300 px-4 py-2">When Applied</th>
<th className="border border-gray-300 px-4 py-2">Organization</th>
<th className="border border-gray-300 px-4 py-2">Action</th>
</tr>
</thead>
<tbody>
Expand All @@ -61,6 +63,14 @@ function MyApplications() {
>
Go to org profile
</td>
<td className="flex flex-row justify-around items-center">
<button type="button" className="text-blue-500 hover:text-blue-700 m-1">
<PencilIcon className="w-5 h-5 sm:w-4 sm:h-4" />
</button>
<button type="button" className="text-red-500 hover:text-red-700">
<TrashIcon className="w-5 h-5 sm:w-4 sm:h-4" />
</button>
</td>
</tr>
))}
</tbody>
Expand Down
4 changes: 2 additions & 2 deletions front-end/src/schemas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export const organizationSchema = yup.object({
.required('Website is required')
.matches(/^(https?:\/\/)?(www\.)?[a-zA-Z0-9-]+\.[a-zA-Z]{2,}$/, 'Enter a valid URL'),
service_ids: yup.array().of(yup.number()).min(1, 'Select at least one service').required('Services are required'),
mission: yup.string().required('Mission statement is required').max(500),
description: yup.string().required('Organization description is required').max(500),
mission: yup.string().required('Mission statement is required').max(255),
description: yup.string().required('Organization description is required').max(255),
});

export const volunteerSchema = yup.object().shape({
Expand Down
4 changes: 2 additions & 2 deletions front-end/src/utils/apiReqests.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,14 +464,14 @@ export const createVolunteerApplication = async (values, volunteerId, requestId)
}
};

export const getMyApplications = async ({ volunteerId }) => {
export const getMyApplications = async (volunteerId) => {
const x_csrf_token = localStorage.getItem('x_csrf_token') ? localStorage.getItem('x_csrf_token') : null;

if (!x_csrf_token) {
throw new Error('CSRF token not found. Ensure it is set correctly in cookies.');
}
try {
const url = `${API_BASE_URL}volunteers/${volunteerId}/volunteer_applications`;
const url = `${API_BASE_URL}volunteer_applications?volunteer_id=${volunteerId}`;
const response = await axios.get(url, {
headers: {
'X-CSRF-Token': x_csrf_token,
Expand Down

0 comments on commit 6470ca0

Please sign in to comment.