fix bug where contact page did not respond
This commit is contained in:
parent
a430c81624
commit
b4da6b9729
@ -4,7 +4,6 @@ from typing import Optional
|
||||
from rio import Text, Column, TextStyle, Component, event, TextInput, MultiLineTextInput, Row, Button
|
||||
|
||||
from src.ez_lan_manager import ConfigurationService, UserService, MailingService
|
||||
from src.ez_lan_manager.components.AnimatedText import AnimatedText
|
||||
from src.ez_lan_manager.components.MainViewContentBox import MainViewContentBox
|
||||
from src.ez_lan_manager.types.SessionStorage import SessionStorage
|
||||
from src.ez_lan_manager.types.User import User
|
||||
@ -17,6 +16,13 @@ class ContactPage(Component):
|
||||
display_printing: list[bool] = [False]
|
||||
user: Optional[User] = None
|
||||
|
||||
e_mail: str = ""
|
||||
subject: str = ""
|
||||
message: str = ""
|
||||
submit_button_is_loading: bool = False
|
||||
response_message: str = ""
|
||||
is_success: bool = True
|
||||
|
||||
@event.on_populate
|
||||
async def on_populate(self) -> None:
|
||||
await self.session.set_title(f"{self.session[ConfigurationService].get_lan_info().name} - Kontakt")
|
||||
@ -24,73 +30,68 @@ class ContactPage(Component):
|
||||
self.user = await self.session[UserService].get_user(self.session[SessionStorage].user_id)
|
||||
else:
|
||||
self.user = None
|
||||
self.e_mail = "" if not self.user else self.user.user_mail
|
||||
|
||||
async def on_send_pressed(self) -> None:
|
||||
error_msg = ""
|
||||
self.submit_button.is_loading = True
|
||||
self.submit_button.force_refresh()
|
||||
self.submit_button_is_loading = True
|
||||
now = datetime.now()
|
||||
if not self.email_input.text:
|
||||
if not self.e_mail:
|
||||
error_msg = "E-Mail darf nicht leer sein!"
|
||||
elif not self.subject_input.text:
|
||||
elif not self.subject:
|
||||
error_msg = "Betreff darf nicht leer sein!"
|
||||
elif not self.message_input.text:
|
||||
elif not self.message:
|
||||
error_msg = "Nachricht darf nicht leer sein!"
|
||||
elif (now - self.last_message_sent[0]) < timedelta(minutes=1):
|
||||
error_msg = "Immer mit der Ruhe!"
|
||||
|
||||
if error_msg:
|
||||
self.submit_button.is_loading = False
|
||||
await self.animated_text.display_text(False, error_msg)
|
||||
print(error_msg)
|
||||
self.submit_button_is_loading = False
|
||||
self.is_success = False
|
||||
self.response_message = error_msg
|
||||
return
|
||||
|
||||
mail_recipient = self.session[ConfigurationService].get_lan_info().organizer_mail
|
||||
msg = (f"Kontaktformular vom {now.strftime('%d.%m.%Y %H:%M')}:\n\n"
|
||||
f"Betreff: {self.subject_input.text}\n"
|
||||
f"Absender: {self.email_input.text}\n\n"
|
||||
f"Betreff: {self.subject}\n"
|
||||
f"Absender: {self.e_mail}\n\n"
|
||||
f"Inhalt:\n"
|
||||
f"{self.message_input.text}\n")
|
||||
|
||||
f"{self.message}\n")
|
||||
await self.session[MailingService].send_email("Kontaktformular-Mitteilung", msg, mail_recipient)
|
||||
self.last_message_sent[0] = datetime.now()
|
||||
self.submit_button.is_loading = False
|
||||
await self.animated_text.display_text(True, "Nachricht erfolgreich gesendet!")
|
||||
self.submit_button_is_loading = False
|
||||
self.is_success = True
|
||||
self.response_message = "Nachricht erfolgreich gesendet!"
|
||||
|
||||
def build(self) -> Component:
|
||||
self.animated_text = AnimatedText(
|
||||
margin_top=2,
|
||||
margin_bottom=1,
|
||||
align_x=0.1
|
||||
)
|
||||
|
||||
self.email_input = TextInput(
|
||||
email_input = TextInput(
|
||||
label="E-Mail Adresse",
|
||||
text="" if not self.user else self.user.user_mail,
|
||||
text=self.bind().e_mail,
|
||||
margin_left=1,
|
||||
margin_right=1,
|
||||
margin_bottom=1,
|
||||
grow_x=True
|
||||
)
|
||||
|
||||
self.subject_input = TextInput(
|
||||
subject_input = TextInput(
|
||||
label="Betreff",
|
||||
text="",
|
||||
text=self.bind().subject,
|
||||
margin_left=1,
|
||||
margin_right=1,
|
||||
margin_bottom=1,
|
||||
grow_x=True
|
||||
)
|
||||
|
||||
self.message_input = MultiLineTextInput(
|
||||
message_input = MultiLineTextInput(
|
||||
label="Deine Nachricht an uns",
|
||||
text="",
|
||||
text=self.bind().message,
|
||||
margin_left=1,
|
||||
margin_right=1,
|
||||
margin_bottom=1,
|
||||
min_height=5
|
||||
)
|
||||
|
||||
self.submit_button = Button(
|
||||
submit_button = Button(
|
||||
content=Text(
|
||||
"Absenden",
|
||||
style=TextStyle(fill=self.session.theme.success_color, font_size=0.9),
|
||||
@ -102,7 +103,8 @@ class ContactPage(Component):
|
||||
shape="rectangle",
|
||||
style="major",
|
||||
color="primary",
|
||||
on_press=self.on_send_pressed
|
||||
on_press=self.on_send_pressed,
|
||||
is_loading=self.bind().submit_button_is_loading
|
||||
)
|
||||
return Column(
|
||||
MainViewContentBox(
|
||||
@ -117,12 +119,21 @@ class ContactPage(Component):
|
||||
margin_bottom=1,
|
||||
align_x=0.5
|
||||
),
|
||||
self.email_input,
|
||||
self.subject_input,
|
||||
self.message_input,
|
||||
email_input,
|
||||
subject_input,
|
||||
message_input,
|
||||
Row(
|
||||
self.animated_text,
|
||||
self.submit_button,
|
||||
Text(
|
||||
text=self.bind().response_message,
|
||||
style=TextStyle(
|
||||
fill=self.session.theme.success_color if self.is_success else self.session.theme.danger_color,
|
||||
font_size=0.9
|
||||
),
|
||||
margin_top=2,
|
||||
margin_bottom=1,
|
||||
align_x=0.1
|
||||
),
|
||||
submit_button,
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user