|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Ajax\Web\Tontine\Guest; |
|
4
|
|
|
|
|
5
|
|
|
use App\Ajax\CallableClass; |
|
6
|
|
|
use Siak\Tontine\Service\Tontine\GuestService; |
|
7
|
|
|
use Siak\Tontine\Validation\Tontine\GuestInviteValidator; |
|
8
|
|
|
|
|
9
|
|
|
use function Jaxon\jq; |
|
10
|
|
|
use function Jaxon\pm; |
|
11
|
|
|
use function trans; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @databag invite |
|
15
|
|
|
*/ |
|
16
|
|
|
class Invite extends CallableClass |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var GuestInviteValidator |
|
20
|
|
|
*/ |
|
21
|
|
|
protected GuestInviteValidator $validator; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param GuestService $guestService |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct(private GuestService $guestService) |
|
27
|
|
|
{} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @after hideMenuOnMobile |
|
31
|
|
|
*/ |
|
32
|
|
|
public function home() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->response->html('section-title', trans('tontine.menus.tontines')); |
|
35
|
|
|
$this->response->html('content-home', $this->render('pages.invite.home')); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
$this->jq('#btn-host-invite-create')->click($this->rq()->add()); |
|
38
|
|
|
$this->jq('#btn-host-invites-refresh')->click($this->rq()->hosts()); |
|
39
|
|
|
$this->jq('#btn-guest-invites-refresh')->click($this->rq()->guests()); |
|
40
|
|
|
|
|
41
|
|
|
$this->hosts(); |
|
42
|
|
|
$this->guests(); |
|
43
|
|
|
|
|
44
|
|
|
return $this->response; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function hosts(int $pageNumber = 0) |
|
48
|
|
|
{ |
|
49
|
|
|
$inviteCount = $this->guestService->getHostInviteCount(); |
|
50
|
|
|
[$pageNumber, $perPage] = $this->pageNumber($pageNumber, $inviteCount, 'invite', 'host.page'); |
|
51
|
|
|
$invites = $this->guestService->getHostInvites($pageNumber); |
|
52
|
|
|
$pagination = $this->rq()->hosts()->paginate($pageNumber, $perPage, $inviteCount); |
|
53
|
|
|
|
|
54
|
|
|
$html = $this->render('pages.invite.host.page', [ |
|
55
|
|
|
'invites' => $invites, |
|
56
|
|
|
'pagination' => $pagination, |
|
57
|
|
|
]); |
|
58
|
|
|
$this->response->html('content-host-invites-page', $html); |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
$inviteId = jq()->parent()->attr('data-invite-id')->toInt(); |
|
61
|
|
|
$this->jq('.btn-host-invite-access')->click($this->rq(Access::class)->home($inviteId)); |
|
62
|
|
|
$this->jq('.btn-host-invite-cancel')->click($this->rq()->cancel($inviteId) |
|
63
|
|
|
->confirm(trans('tontine.invite.questions.cancel'))); |
|
64
|
|
|
$this->jq('.btn-host-invite-delete')->click($this->rq()->hostDelete($inviteId) |
|
65
|
|
|
->confirm(trans('tontine.invite.questions.delete'))); |
|
66
|
|
|
|
|
67
|
|
|
return $this->response; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function guests(int $pageNumber = 0) |
|
71
|
|
|
{ |
|
72
|
|
|
$inviteCount = $this->guestService->getGuestInviteCount(); |
|
73
|
|
|
[$pageNumber, $perPage] = $this->pageNumber($pageNumber, $inviteCount, 'invite', 'guest.page'); |
|
74
|
|
|
$invites = $this->guestService->getGuestInvites($pageNumber); |
|
75
|
|
|
$pagination = $this->rq()->guests()->paginate($pageNumber, $perPage, $inviteCount); |
|
76
|
|
|
|
|
77
|
|
|
$html = $this->render('pages.invite.guest.page', [ |
|
78
|
|
|
'invites' => $invites, |
|
79
|
|
|
'pagination' => $pagination, |
|
80
|
|
|
]); |
|
81
|
|
|
$this->response->html('content-guest-invites-page', $html); |
|
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
$inviteId = jq()->parent()->attr('data-invite-id')->toInt(); |
|
84
|
|
|
$this->jq('.btn-guest-invite-accept')->click($this->rq()->accept($inviteId) |
|
85
|
|
|
->confirm(trans('tontine.invite.questions.accept'))); |
|
86
|
|
|
$this->jq('.btn-guest-invite-refuse')->click($this->rq()->refuse($inviteId) |
|
87
|
|
|
->confirm(trans('tontine.invite.questions.refuse'))); |
|
88
|
|
|
$this->jq('.btn-guest-invite-delete')->click($this->rq()->guestDelete($inviteId) |
|
89
|
|
|
->confirm(trans('tontine.invite.questions.delete'))); |
|
90
|
|
|
|
|
91
|
|
|
return $this->response; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function add() |
|
95
|
|
|
{ |
|
96
|
|
|
$title = trans('tontine.invite.titles.add'); |
|
97
|
|
|
$content = $this->render('pages.invite.host.add'); |
|
98
|
|
|
$buttons = [[ |
|
99
|
|
|
'title' => trans('common.actions.cancel'), |
|
100
|
|
|
'class' => 'btn btn-tertiary', |
|
101
|
|
|
'click' => 'close', |
|
102
|
|
|
],[ |
|
103
|
|
|
'title' => trans('common.actions.save'), |
|
104
|
|
|
'class' => 'btn btn-primary', |
|
105
|
|
|
'click' => $this->rq()->create(pm()->form('invite-form')), |
|
106
|
|
|
]]; |
|
107
|
|
|
|
|
108
|
|
|
$this->dialog->hide(); |
|
109
|
|
|
$this->dialog->show($title, $content, $buttons); |
|
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
return $this->response; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @di $validator |
|
116
|
|
|
*/ |
|
117
|
|
|
public function create(array $formValues) |
|
118
|
|
|
{ |
|
119
|
|
|
$values = $this->validator->validateItem($formValues); |
|
120
|
|
|
$this->guestService->createInvite($values['email']); |
|
121
|
|
|
|
|
122
|
|
|
$this->dialog->hide(); |
|
123
|
|
|
$this->notify->success(trans('tontine.invite.messages.sent'), trans('common.titles.success')); |
|
124
|
|
|
|
|
125
|
|
|
return $this->hosts(); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function accept(int $inviteId) |
|
129
|
|
|
{ |
|
130
|
|
|
$this->guestService->acceptInvite($inviteId); |
|
131
|
|
|
$this->notify->success(trans('tontine.invite.messages.accepted'), trans('common.titles.success')); |
|
132
|
|
|
|
|
133
|
|
|
return $this->guests(); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function refuse(int $inviteId) |
|
137
|
|
|
{ |
|
138
|
|
|
$this->guestService->refuseInvite($inviteId); |
|
139
|
|
|
$this->notify->success(trans('tontine.invite.messages.refused'), trans('common.titles.success')); |
|
140
|
|
|
|
|
141
|
|
|
return $this->guests(); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function cancel(int $inviteId) |
|
145
|
|
|
{ |
|
146
|
|
|
$this->guestService->cancelInvite($inviteId); |
|
147
|
|
|
$this->notify->success(trans('tontine.invite.messages.cancelled'), trans('common.titles.success')); |
|
148
|
|
|
|
|
149
|
|
|
return $this->hosts(); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function hostDelete(int $inviteId) |
|
153
|
|
|
{ |
|
154
|
|
|
$this->guestService->deleteHostInvite($inviteId); |
|
155
|
|
|
$this->notify->success(trans('tontine.invite.messages.deleted'), trans('common.titles.success')); |
|
156
|
|
|
|
|
157
|
|
|
return $this->hosts(); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
public function guestDelete(int $inviteId) |
|
161
|
|
|
{ |
|
162
|
|
|
if($this->guestService->deleteGuestInvite($inviteId)) |
|
163
|
|
|
{ |
|
164
|
|
|
// The active tontine invite is deleted. Reload the page. |
|
165
|
|
|
$this->response->redirect('/'); |
|
166
|
|
|
return $this->response; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
$this->notify->success(trans('tontine.invite.messages.deleted'), trans('common.titles.success')); |
|
170
|
|
|
return $this->guests(); |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
|