Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement React Query in RecruitmentPositionOverviewpage #1574

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions backend/samfundet/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,26 +1070,40 @@ def put(self, request: Request, pk: int) -> Response:


class RecruitmentApplicationForRecruitmentPositionView(ModelViewSet):
# TODO: refactor this in ISSUE #1575
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I #1575 skal RecruitmentStatusChoices hentes til frontend, så de definterte filter typene her må endres når det blir gjort.

permission_classes = [IsAuthenticated]
serializer_class = RecruitmentApplicationForGangSerializer
queryset = RecruitmentApplication.objects.all()

# TODO: User should only be able to edit the fields that are allowed
# Define filter mappings as a class attribute
FILTER_MAPPINGS = {
'unprocessed': {'withdrawn': False, 'recruiter_status': RecruitmentStatusChoices.NOT_SET},
'withdrawn': {'withdrawn': True},
'hardtoget': {'withdrawn': False, 'recruiter_status': RecruitmentStatusChoices.CALLED_AND_REJECTED},
'accepted': {'withdrawn': False, 'recruiter_status': RecruitmentStatusChoices.CALLED_AND_ACCEPTED},
'rejected': {'withdrawn': False, 'recruiter_status': RecruitmentStatusChoices.REJECTION},
}

def retrieve(self, request: Request, pk: int) -> Response:
"""Returns a list of all the recruitments for the specified gang."""
"""
Retrieve filtered applications for a specific recruitment position.
If no filter_type is provided, returns all applications.

Query Parameters:
- filter_type: string, one of ['unprocessed', 'withdrawn', 'hardtoget', 'accepted', 'rejected']
"""
position = get_object_or_404(RecruitmentPosition, id=pk)
applications = self.get_queryset().filter(recruitment_position=position)

applications = RecruitmentApplication.objects.filter(
recruitment_position=position,
)

# check permissions for each application
applications = get_objects_for_user(user=request.user, perms=['view_recruitmentapplication'], klass=applications)
filter_type = request.query_params.get('filter_type')
if filter_type:
filter_params = self.FILTER_MAPPINGS.get(filter_type)
if not filter_params:
return Response({'error': 'Invalid filter_type parameter'}, status=status.HTTP_400_BAD_REQUEST)
applications = applications.filter(**filter_params)

serializer = self.get_serializer(applications, many=True)
return Response(serializer.data)
return Response(data=serializer.data)


class ActiveRecruitmentPositionsView(ListAPIView):
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Components/Dropdown/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { Dropdown } from './Dropdown';
export type { DropdownProps } from './Dropdown';
export type { DropdownProps, DropdownOption } from './Dropdown';
4 changes: 2 additions & 2 deletions frontend/src/Components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ export { ProgressBar } from './ProgressBar';
export { ProtectedRoute } from './ProtectedRoute';
export { PulseEffect } from './PulseEffect';
export { RadioButton } from './RadioButton';
export { RecruitmentApplicantsStatus } from './RecruitmentApplicantsStatus';
export { RecruitmentWithoutInterviewTable } from './RecruitmentWithoutInterviewTable';
export { RootErrorBoundary } from './RootErrorBoundary';
export { SamfOutlet } from './SamfOutlet';
export { SamfundetLogo } from './SamfundetLogo';
export { SamfundetLogoSpinner } from './SamfundetLogoSpinner';
export { useScrollToTop } from './ScrollToTop';
export { Select } from './Select';
export { SetInterviewManuallyModal } from './SetInterviewManually';
export { Skeleton } from './Skeleton';
export { SpinningBorder } from './SpinningBorder';
export { SplashHeaderBox } from './SplashHeaderBox';
Expand All @@ -89,7 +89,7 @@ export { Video } from './Video';

// Props
export type { CheckboxProps } from './Checkbox';
export type { DropdownProps } from './Dropdown';
export type { DropdownOption, DropdownProps } from './Dropdown';
export type { ImagePickerProps } from './ImagePicker/ImagePicker';
export type { InputFieldProps } from './InputField';
export type { InputFileProps } from './InputFile';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

.sub_container {
margin-top: 1.5em;
}
Expand Down
Loading
Loading