Skip to content

Commit 5f32791

Browse files
authored
Allow organizers to email themselves (#651)
1 parent f3b20d4 commit 5f32791

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

backend/app/Http/Actions/Organizers/Public/SendOrganizerContactMessagePublicAction.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function __invoke(Request $request, int $organizerId): JsonResponse
3030

3131
$this->handler->handle(SendOrganizerContactMessageDTO::from([
3232
'organizer_id' => $organizerId,
33+
'account_id' => $this->getAuthenticatedAccountId(),
3334
'name' => $data['name'],
3435
'email' => $data['email'],
3536
'message' => $data['message'],

backend/app/Services/Application/Handlers/Organizer/DTO/SendOrganizerContactMessageDTO.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class SendOrganizerContactMessageDTO extends BaseDataObject
88
{
99
public function __construct(
1010
public int $organizer_id,
11+
public int $account_id,
1112
public string $name,
1213
public string $email,
1314
public string $message,

backend/app/Services/Application/Handlers/Organizer/SendOrganizerContactMessageHandler.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use HiEvents\Mail\Organizer\OrganizerContactEmail;
77
use HiEvents\Repository\Interfaces\OrganizerRepositoryInterface;
88
use HiEvents\Services\Application\Handlers\Organizer\DTO\SendOrganizerContactMessageDTO;
9-
use HTMLPurifier;
9+
use HiEvents\Services\Infrastructure\HtmlPurifier\HtmlPurifierService;
1010
use Illuminate\Mail\Mailer;
1111
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
1212

@@ -15,7 +15,7 @@ class SendOrganizerContactMessageHandler
1515
public function __construct(
1616
private readonly Mailer $mailer,
1717
private readonly OrganizerRepositoryInterface $organizerRepository,
18-
private readonly HTMLPurifier $purifier,
18+
private readonly HtmlPurifierService $purifier,
1919
)
2020
{
2121
}
@@ -24,7 +24,8 @@ public function handle(SendOrganizerContactMessageDTO $dto): void
2424
{
2525
$organizer = $this->organizerRepository->findById($dto->organizer_id);
2626

27-
if ($organizer->getStatus() !== OrganizerStatus::LIVE->value) {
27+
// Don't allow people to contact organizers that are not live, except for the organizer's own account
28+
if ($organizer->getStatus() !== OrganizerStatus::LIVE->value && $dto->account_id !== $organizer->getAccountId()) {
2829
throw new ResourceNotFoundException(__('Organizer not found'));
2930
}
3031

frontend/src/components/common/ContactOrganizerModal/index.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Organizer} from '../../../types';
66
import {useContactOrganizer} from '../../../mutations/useContactOrganizer';
77
import {showSuccess, showError} from '../../../utilites/notifications';
88
import classes from './ContactOrganizerModal.module.scss';
9+
import {InputGroup} from "../InputGroup";
910

1011
interface ContactOrganizerModalProps {
1112
opened: boolean;
@@ -26,14 +27,19 @@ export const ContactOrganizerModal: React.FC<ContactOrganizerModalProps> = ({
2627
email: '',
2728
message: '',
2829
},
30+
validateInputOnBlur: true,
2931
validate: {
3032
name: (value) => !value ? t`Name is required` : null,
3133
email: (value) => {
3234
if (!value) return t`Email is required`;
3335
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) return t`Invalid email`;
3436
return null;
3537
},
36-
message: (value) => !value ? t`Message is required` : null,
38+
message: (value) => {
39+
if (value.length > 5000) return t`Message cannot exceed 5000 characters`;
40+
41+
return !value ? t`Message is required` : null;
42+
},
3743
},
3844
});
3945

@@ -62,7 +68,7 @@ export const ContactOrganizerModal: React.FC<ContactOrganizerModalProps> = ({
6268
className={classes.contactModal}
6369
>
6470
<form onSubmit={contactForm.onSubmit(handleContactSubmit)}>
65-
<Group grow mb="md">
71+
<InputGroup>
6672
<TextInput
6773
label={t`Your Name`}
6874
placeholder={t`Enter your name`}
@@ -76,13 +82,15 @@ export const ContactOrganizerModal: React.FC<ContactOrganizerModalProps> = ({
7682
type="email"
7783
{...contactForm.getInputProps('email')}
7884
/>
79-
</Group>
85+
</InputGroup>
8086

8187
<Textarea
8288
label={t`Message`}
8389
placeholder={t`Write your message here...`}
8490
required
8591
minRows={4}
92+
autosize
93+
maxLength={5001}
8694
mb="md"
8795
{...contactForm.getInputProps('message')}
8896
/>
@@ -107,4 +115,4 @@ export const ContactOrganizerModal: React.FC<ContactOrganizerModalProps> = ({
107115
</form>
108116
</Modal>
109117
);
110-
};
118+
};

0 commit comments

Comments
 (0)