Skip to content

Commit

Permalink
Merge pull request #845 from ita-social-projects/#761-Contact-Adminis…
Browse files Browse the repository at this point in the history
…trator-via-ZvorotiyZvyazok-page-backend

#761 contact administrator via zvorotiy zvyazok page backend
  • Loading branch information
KuzykY authored Oct 24, 2024
2 parents 401581c + 628cab9 commit 77897c7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 30 deletions.
18 changes: 6 additions & 12 deletions BackEnd/administration/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib.auth import get_user_model
from rest_framework import serializers
from utils.administration.feedback_category import FeedbackCategory
from authentication.models import CustomUser
from profiles.models import (
Profile,
Expand Down Expand Up @@ -197,25 +198,18 @@ class Meta:
class FeedbackSerializer(serializers.Serializer):
email = serializers.EmailField(
required=True,
error_messages={
"required": "Будь ласка, вкажіть правильну адресу електронної скриньки."
},
error_messages={"required": "Please provide a valid email address."},
)
message = serializers.CharField(
min_length=10,
required=True,
error_messages={
"required": "Повідомлення не може бути порожнім.",
"min_length": "Повідомлення не може бути коротшим за 10 символів.",
"required": "Message cannot be empty.",
"min_length": "Message must be at least 10 characters long.",
},
)
category = serializers.ChoiceField(
choices=[
("Технічне питання", "Технічне питання"),
("Рекомендації", "Рекомендації"),
("Питання", "Питання"),
("Інше", "Інше"),
],
choices=FeedbackCategory.choices(),
required=True,
error_messages={"required": "Будь ласка, оберіть тип повідомлення."},
error_messages={"required": "Please select a category."},
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<div class="email-container">
<img src="{{protocol}}://178.212.110.52/craftMerge-logo.png" alt="CRAFTMERGE" />

<h2>Нове повідомлення від {{ user_email }}</h2>
<p>Нове повідомлення від {{ user_email }}<p>

<p><b>Категорія:</b> {{ category }}</p>
<p><b>Повідомлення:</b></p>
Expand Down
30 changes: 17 additions & 13 deletions BackEnd/administration/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,24 @@ class CreateAdminUserView(CreateAPIView):
serializer_class = AdminRegistrationSerializer


class FeedbackView(APIView):
def post(self, request):
serializer = FeedbackSerializer(data=request.data)
class FeedbackView(CreateAPIView):
serializer_class = FeedbackSerializer

if serializer.is_valid():
email = serializer.validated_data["email"]
message = serializer.validated_data["message"]
category = serializer.validated_data["category"]
def perform_create(self, serializer):
"""
Performs the creation of a new feedback record and sends an email notification.
send_email_feedback(email, message, category)
Parameters:
- serializer (FeedbackSerializer): The serializer instance containing validated data.
return Response(
{"message": "Ваше повідомлення надіслано успішно!"},
status=status.HTTP_200_OK,
)
Returns:
None
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
This method extracts the email, message, and category from the validated data in the serializer.
It then calls the `send_email_feedback` function to send an email notification with the provided feedback details.
"""
email = serializer.validated_data["email"]
message = serializer.validated_data["message"]
category = serializer.validated_data["category"]

send_email_feedback(email, message, category)
12 changes: 12 additions & 0 deletions BackEnd/utils/administration/feedback_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from enum import Enum


class FeedbackCategory(Enum):
TECHNICAL = "Технічне питання"
RECOMMENDATION = "Рекомендації"
QUESTION = "Питання"
OTHER = "Інше"

@classmethod
def choices(cls):
return [(category.value, category.value) for category in cls]
8 changes: 4 additions & 4 deletions FrontEnd/src/components/Contact/Contact.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ const Contact = () => {
}, [percent]);

const categoryOptions = [
{ id: 1, name: 'Технічне питання' },
{ id: 2, name: 'Рекомендації' },
{ id: 3, name: 'Питання' },
{ id: 4, name: 'Інше' },
{ id: 'TECHNICAL', name: 'Технічне питання' },
{ id: 'RECOMMENDATION', name: 'Рекомендації' },
{ id: 'QUESTION', name: 'Питання' },
{ id: 'OTHER', name: 'Інше' },
];

const handleEmailChange = (e) => {
Expand Down

0 comments on commit 77897c7

Please sign in to comment.