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

#79 - Inviting to quizzes frontend #124

Merged
merged 231 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
231 commits
Select commit Hold shift + click to select a range
86bf145
Add invite vue, controller, resource for admin panel
PrabuckiDominik Sep 6, 2024
656d053
fix code style
PrabuckiDominik Sep 6, 2024
b61b1c7
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
PrabuckiDominik Sep 6, 2024
dd9095a
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
PrabuckiDominik Sep 9, 2024
3fd3a2f
add pagination
PrabuckiDominik Sep 9, 2024
0a2ffbc
Move logic to quiz
PrabuckiDominik Sep 9, 2024
575416d
Add invitation
PrabuckiDominik Sep 9, 2024
45f3b98
Reset password now queue
PrabuckiDominik Sep 10, 2024
89c4472
Add invite user to quiz is queued
PrabuckiDominik Sep 10, 2024
b682746
Add jobs for sending mails
PrabuckiDominik Sep 10, 2024
af069f3
Update quiz policy
PrabuckiDominik Sep 10, 2024
a4af77d
Fix invite title
PrabuckiDominik Sep 10, 2024
dae1f07
Fix code style
PrabuckiDominik Sep 10, 2024
db94388
Add sort by name/surname with watch
PrabuckiDominik Sep 11, 2024
2e1b01e
Fix password notification link
PrabuckiDominik Sep 11, 2024
4b00c7b
Fix search while sorting by school
PrabuckiDominik Sep 11, 2024
c059f53
Fix searchbar
PrabuckiDominik Sep 11, 2024
b13dac5
Add limit to filter
PrabuckiDominik Sep 11, 2024
c349688
Add assignment to test while inviting user to it
PrabuckiDominik Sep 11, 2024
e8ca731
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
PrabuckiDominik Sep 11, 2024
ffaa248
Fix issue in policy, allowing publish ranking without quiz being publ…
PrabuckiDominik Sep 11, 2024
82591c8
Fix tests
PrabuckiDominik Sep 11, 2024
fe0299f
Fix code style
PrabuckiDominik Sep 11, 2024
eafae0b
Add assign button to quiz without sending mail to users
PrabuckiDominik Sep 11, 2024
e8c008e
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
PrabuckiDominik Oct 19, 2024
599e3f3
create basic crud layout
AmonDeShir Oct 21, 2024
8c831c0
refactor: decouple from 'demo' and '87-login-page-improvements' branches
JokeUrSelf Oct 14, 2024
e9c5ba3
fix: duration input is cut when expanding the test
Oct 18, 2024
2df9491
fix: duration can be set to number the exceeds the max limit
JokeUrSelf Oct 18, 2024
02d21cd
fix: remove copying for multiple quizzes
JokeUrSelf Oct 18, 2024
44d976f
fix: delete button deletes all questions
JokeUrSelf Oct 18, 2024
ecce6b4
style: answer check button color and position
JokeUrSelf Oct 18, 2024
9cbc5fb
style: create new answers with empty content
JokeUrSelf Oct 18, 2024
27caa34
build: update packages
JokeUrSelf Oct 18, 2024
6289fa1
fix: linting
JokeUrSelf Oct 18, 2024
b590f15
chore: merge button logic
JokeUrSelf Oct 18, 2024
d2d0d0f
fix: remove time limits for datepicker
JokeUrSelf Oct 18, 2024
6729c1e
fix: error message is not fully visible
JokeUrSelf Oct 18, 2024
6b3009f
fix: `schedule_at` error message contains untranslated word 'now'
JokeUrSelf Oct 18, 2024
71d75d2
fix: wrong interpritation of time after quiz update
JokeUrSelf Oct 18, 2024
ef5c86a
style: add animation to quizzes occurence
JokeUrSelf Oct 18, 2024
ba61f3c
format: remove unused import
JokeUrSelf Oct 18, 2024
d0d09b7
style: add animations for icon-buttons
JokeUrSelf Oct 19, 2024
d8f7f79
apply suggestion: change 'Stworzony' na 'Utworzony'
JokeUrSelf Oct 19, 2024
768c34a
fix: sorting isn' t preserved after page reload
JokeUrSelf Oct 19, 2024
16e7702
fix: deletion alert doesn't close when clicking "Usuń"
JokeUrSelf Oct 19, 2024
3b6b0ac
chore: preserve state and scroll in request components by default
JokeUrSelf Oct 19, 2024
6db15d5
fix: seeder creates quizzes that can't exist
JokeUrSelf Oct 19, 2024
8d27ffb
feat: add placeholders for empty textareas
JokeUrSelf Oct 20, 2024
d1af3e9
fix: "Zaproś uczestników" redirects to entry that doesn't yet exist
JokeUrSelf Oct 21, 2024
949ad49
fix: typo in "Zaproś uczestników"
JokeUrSelf Oct 21, 2024
9f5255a
feat: add sorting by modification
JokeUrSelf Oct 21, 2024
c3a8e97
feat: make pre-publish validation message more specific
JokeUrSelf Oct 21, 2024
5b765ff
fix: publish button doesn't switch its state
JokeUrSelf Oct 21, 2024
b81932f
feat: add " - kopia" to the end of the tile of a copied quiz
JokeUrSelf Oct 21, 2024
b3e5014
format: `"` to `'`
JokeUrSelf Oct 21, 2024
6bc7c03
fix: sorting state is preserved between sessions
JokeUrSelf Oct 22, 2024
62d6cbe
style: change 'Nie można oddać testu.' to 'Nie można opublikować testu.'
JokeUrSelf Oct 22, 2024
1f19208
refactor: suggestions from code review
JokeUrSelf Oct 25, 2024
e376e2b
chore: add archieved quizzes to seeder
JokeUrSelf Oct 29, 2024
a619699
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
PrabuckiDominik Nov 1, 2024
51e8afa
build: update packages
JokeUrSelf Nov 7, 2024
2445ab1
feat: add dropdown pointer positioning
JokeUrSelf Nov 7, 2024
e383a25
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
JokeUrSelf Nov 7, 2024
874df44
Merge branch 'main' into 26-admin-panel-for-managing-tests-frontend
JokeUrSelf Nov 8, 2024
6428de8
fix: quiz title underline
JokeUrSelf Nov 8, 2024
be7e0bb
Merge branch '26-admin-panel-for-managing-tests-frontend' of https://…
AmonDeShir Nov 8, 2024
46d26e0
fix: duration input doesn't resize fully
JokeUrSelf Nov 8, 2024
87005a7
feat: error handle empty question
JokeUrSelf Nov 9, 2024
e877fce
refactor: link button styling
JokeUrSelf Nov 9, 2024
e219f2f
create warning message box
AmonDeShir Nov 9, 2024
2063823
move sorting logic to a separate helper
AmonDeShir Nov 9, 2024
8d41573
fix: cloning doesn't add data to database
JokeUrSelf Nov 9, 2024
38b669b
fix: error highliting on question deletion reappears on the next ques…
JokeUrSelf Nov 9, 2024
b4740c9
feat: automatically remove empty answers
JokeUrSelf Nov 9, 2024
df8d86a
fix: revert update logic
JokeUrSelf Nov 9, 2024
85734d9
create basic crud for schools
AmonDeShir Nov 9, 2024
7f36b82
Merge branch '26-admin-panel-for-managing-tests-frontend' of https://…
AmonDeShir Nov 9, 2024
f90179f
simplify quizzes page
AmonDeShir Nov 9, 2024
c9eaa29
fix linter errors
AmonDeShir Nov 9, 2024
820d24e
fix code style
AmonDeShir Nov 9, 2024
ddfbc8d
rename value to address
AmonDeShir Nov 9, 2024
41cf1a7
add regon to school
AmonDeShir Nov 9, 2024
bc14211
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
AmonDeShir Nov 9, 2024
d5bf673
fix code style
AmonDeShir Nov 9, 2024
0f8bebc
add lintf
AmonDeShir Nov 10, 2024
95b2ba8
create mobile version
AmonDeShir Nov 10, 2024
ee7d7b3
add newItem slot
AmonDeShir Nov 10, 2024
7a006d5
remove limit from school controller
AmonDeShir Nov 10, 2024
a8d6014
create CrudInput
AmonDeShir Nov 10, 2024
00cb5a9
fix InputWrapper
AmonDeShir Nov 10, 2024
073b20a
remove force-full-screen-nav
AmonDeShir Nov 10, 2024
6c9d414
add prop pointer-position to Dropdown
AmonDeShir Nov 10, 2024
55d1251
change import button icon
AmonDeShir Nov 10, 2024
a152140
improve code style
AmonDeShir Nov 10, 2024
5c047d7
add comments explaining textarea height reset
AmonDeShir Nov 10, 2024
d5daa9d
Replace ButtonFrame with Button
AmonDeShir Nov 10, 2024
3a9f5af
allow manual implementation of the 'New Item' button
AmonDeShir Nov 10, 2024
ac1b740
improve ButtonFrame
AmonDeShir Nov 10, 2024
add105f
fix code style
AmonDeShir Nov 10, 2024
12a21d6
move resize none to vDynamicTextAreaHeight.ts
AmonDeShir Nov 11, 2024
c16daea
fix InputWrapper
AmonDeShir Nov 11, 2024
abc8723
add padding to ButtonFrame
AmonDeShir Nov 11, 2024
7331358
fix linter errors
AmonDeShir Nov 11, 2024
7fb771e
fix new item mode
AmonDeShir Nov 11, 2024
26eeb6c
Update resources/js/Pages/Admin/SchoolsPanel.vue
AmonDeShir Nov 12, 2024
4f03066
add regon validator
AmonDeShir Nov 20, 2024
b6b3e39
fix school seeder
AmonDeShir Nov 20, 2024
f48d1d0
fix code style
AmonDeShir Nov 20, 2024
a7b5e1c
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
AmonDeShir Nov 20, 2024
a490700
add zip-code input
AmonDeShir Nov 22, 2024
1669643
validate the length of the inputs
AmonDeShir Nov 22, 2024
7265086
create icon button
AmonDeShir Nov 23, 2024
5e195e1
create SortHelper
AmonDeShir Nov 24, 2024
e62ec08
add pagination to CRUDPage
AmonDeShir Nov 25, 2024
7d0876b
fix tests
AmonDeShir Nov 25, 2024
03a3ddb
fix abort mock
AmonDeShir Nov 25, 2024
fafdf7d
fix test
AmonDeShir Nov 25, 2024
ec3e31b
fix abort mock
AmonDeShir Nov 25, 2024
8102f70
fix test
AmonDeShir Nov 25, 2024
ae73b5c
add information about the number of fetched schools
AmonDeShir Nov 25, 2024
d675bd9
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
PrabuckiDominik Nov 25, 2024
2432553
make filter case-insensitive
AmonDeShir Nov 26, 2024
5fd4acc
debounce searchbar
AmonDeShir Nov 26, 2024
9611a30
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
AmonDeShir Nov 26, 2024
3d41108
fix code style
AmonDeShir Nov 26, 2024
2cb0aed
fix sort test
AmonDeShir Nov 26, 2024
05e8ccd
add icon button
AmonDeShir Nov 26, 2024
6a6063e
rename QuizLayout to QuizPage
AmonDeShir Nov 26, 2024
20d4104
fix unsupported_field translation
AmonDeShir Nov 26, 2024
9f0fb79
fix sorter href
AmonDeShir Nov 26, 2024
cfedfb7
create no content component
AmonDeShir Nov 26, 2024
562b537
fix crud cancel button
AmonDeShir Nov 26, 2024
aabc799
rename ExapnsionToggleDynamicIcon to ExpansionToggleDynamicIcon
AmonDeShir Nov 26, 2024
388bb2c
hide delete button if quiz is locked
AmonDeShir Nov 26, 2024
f7b3bd1
change user name to firstname
AmonDeShir Nov 26, 2024
6fb2914
fix code style
AmonDeShir Nov 26, 2024
09ecd40
fix NoContent
AmonDeShir Nov 26, 2024
858c8b8
fix typo
AmonDeShir Nov 26, 2024
e49acce
Cleanup code, add unassign button and tests
PrabuckiDominik Nov 26, 2024
60d0a02
Update resources/js/Pages/Admin/Quizzes.vue
AmonDeShir Nov 26, 2024
bc67325
Use school resource
PrabuckiDominik Nov 26, 2024
9fb5214
merge branch 50-crud-for-schools-frontend
AmonDeShir Dec 1, 2024
7c70f46
fix invite button
AmonDeShir Dec 1, 2024
6431cf2
update rspo api url
AmonDeShir Dec 2, 2024
3322e8a
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
AmonDeShir Dec 2, 2024
ba33db2
merge branch main
AmonDeShir Dec 2, 2024
e7c9aa4
style: change searchbar design
JokeUrSelf Dec 2, 2024
4643070
Apply changes from code review
PrabuckiDominik Dec 2, 2024
219e66b
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
PrabuckiDominik Dec 2, 2024
2132e47
Remove unused file
PrabuckiDominik Dec 2, 2024
d4bc52c
invite draft
AmonDeShir Dec 3, 2024
5d45523
merge branch 50-crud-for-schools-frontend
AmonDeShir Dec 3, 2024
35e5166
merge branch 80-inviting-to-quizzes-backend into inviting-to-quizzes-…
AmonDeShir Dec 3, 2024
6d6e46c
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
AmonDeShir Dec 3, 2024
8c1d2a0
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
AmonDeShir Dec 3, 2024
225a276
style: searchbar
JokeUrSelf Dec 4, 2024
7a5936b
fix: absence of dynamic colors
JokeUrSelf Dec 4, 2024
b844f6e
fix: login and regestration aren't the same size
JokeUrSelf Dec 5, 2024
7a1b7d7
style
JokeUrSelf Dec 5, 2024
37cdcb2
fix: semantics
JokeUrSelf Dec 5, 2024
dcfd9f5
feat (raw): pagination for searchbar on homepage
JokeUrSelf Dec 6, 2024
8e303b0
feat: mode switch of a searchbar
JokeUrSelf Dec 6, 2024
92a2ab4
style: responsiveness
JokeUrSelf Dec 6, 2024
d352763
refactor: readability
JokeUrSelf Dec 6, 2024
0b6173a
feat: extended linter wih the built-in extra rules
JokeUrSelf Dec 6, 2024
ed7c811
refactor: `useSorter` to `useQuery`
JokeUrSelf Dec 7, 2024
b4d61dc
fix: searchbar doesn't fetch all searches
JokeUrSelf Dec 7, 2024
73a3331
fix: archived quizzes button doesn't react
JokeUrSelf Dec 7, 2024
2611982
refactor
JokeUrSelf Dec 7, 2024
1daa3d6
change: password to seeder account from "password" to "interns2024b"
JokeUrSelf Dec 7, 2024
74bc646
fix: make fix
JokeUrSelf Dec 7, 2024
52f0f7d
pfffffffffffffffffffff
JokeUrSelf Dec 11, 2024
06a1081
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
JokeUrSelf Dec 11, 2024
cea4c64
suggestions from CR
JokeUrSelf Dec 11, 2024
87aa166
redisgned buttons
JokeUrSelf Dec 12, 2024
6912d29
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
JokeUrSelf Dec 12, 2024
5ad7205
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
JokeUrSelf Dec 12, 2024
3748403
remove unused prop
JokeUrSelf Dec 12, 2024
ad90e68
fix test
JokeUrSelf Dec 12, 2024
d4b059f
feat: add link to tauron on a homepage
JokeUrSelf Dec 12, 2024
97d5ce4
improve answers colors in Quiz
JokeUrSelf Dec 12, 2024
ddcc6d1
add theme switch to the user settings
JokeUrSelf Dec 12, 2024
461b118
refactor link button
JokeUrSelf Dec 12, 2024
1f61511
manage icons in button frame
JokeUrSelf Dec 12, 2024
2ff4dc3
fix: search bar modes don't work
JokeUrSelf Dec 12, 2024
3120f3c
add return type to `searchQuery`
JokeUrSelf Dec 12, 2024
2ddec75
rename a function
JokeUrSelf Dec 12, 2024
67cb57c
change the logo color
JokeUrSelf Dec 12, 2024
99034e1
limit the token size
JokeUrSelf Dec 12, 2024
015d683
lintf
JokeUrSelf Dec 12, 2024
e37e401
redesign profile page
JokeUrSelf Dec 12, 2024
1256fa5
fix: schools loading covers nav buttons in header
JokeUrSelf Dec 12, 2024
72503b6
fix: disabled schools are not shown
JokeUrSelf Dec 12, 2024
468a79e
fix: the searchbar doesn't close when clicking on area above it
JokeUrSelf Dec 12, 2024
1cbdd30
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
AmonDeShir Dec 13, 2024
6277280
Merge branch 'main' into inviting-to-quizzes-frontend
JokeUrSelf Dec 14, 2024
b7dfe63
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
AmonDeShir Dec 15, 2024
955fb1d
replace switch with select
AmonDeShir Dec 16, 2024
5796684
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
AmonDeShir Dec 16, 2024
4fa043b
feat: enhance and reuse CrudInput. Add pagination to CrudSchoolInput
JokeUrSelf Dec 17, 2024
582573d
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
JokeUrSelf Dec 17, 2024
6b74b53
replace switch with select
AmonDeShir Dec 16, 2024
d034dd7
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
AmonDeShir Dec 17, 2024
b1e701c
fix tests
AmonDeShir Dec 17, 2024
bc1d880
feat: change theme for error pages
JokeUrSelf Dec 18, 2024
27bb0a4
add `odznacz wszystkich` label state
JokeUrSelf Dec 18, 2024
b70ff99
feat: add infromation which quiz the users are invited to
JokeUrSelf Dec 18, 2024
2cecc4d
fix: schools list in UsersPanel is too wide
JokeUrSelf Dec 18, 2024
420be92
style: make quiz visibility value smaller
JokeUrSelf Dec 18, 2024
1d50113
revert: checkbox on homepage
JokeUrSelf Dec 18, 2024
e29bb9d
fix: `CrudInput` error isn't shown
JokeUrSelf Dec 18, 2024
0429fdd
make the process of selecting quiz visibility quicker for the admin
JokeUrSelf Dec 18, 2024
da3c9b8
add transition when switching a theme
JokeUrSelf Dec 18, 2024
b95bcf0
style: profile responsiveness
JokeUrSelf Dec 18, 2024
061a37f
change user password
AmonDeShir Dec 18, 2024
655f58a
remove unused method
AmonDeShir Dec 18, 2024
575cf40
style: redesign sidebar
JokeUrSelf Dec 18, 2024
91310c2
fix: gaps
JokeUrSelf Dec 18, 2024
cf03330
fix: make fix-all
JokeUrSelf Dec 18, 2024
f300e3d
revert: `Divider` responsiveness
JokeUrSelf Dec 18, 2024
0cc2c17
Merge branch 'inviting-to-quizzes-frontend' of https://github.com/blu…
AmonDeShir Dec 18, 2024
f5836cf
add quiz selection
AmonDeShir Dec 18, 2024
d30a6e3
fix: no scrollbar
JokeUrSelf Dec 19, 2024
6647457
Merge branch 'inviting-to-quizzes-frontend' of https://github.com/blu…
JokeUrSelf Dec 19, 2024
59ea7d7
add email notification for quiz invite
AmonDeShir Dec 19, 2024
255c3f2
Merge branch 'inviting-to-quizzes-frontend' of https://github.com/blu…
AmonDeShir Dec 19, 2024
a1d1945
fix tests
AmonDeShir Dec 19, 2024
09f6c54
Update app/Http/Controllers/InviteController.php
AmonDeShir Dec 20, 2024
14b23ed
add go to quiz button
AmonDeShir Dec 20, 2024
761a111
fix code style
AmonDeShir Dec 20, 2024
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
7 changes: 6 additions & 1 deletion app/Actions/AssignToQuizAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Actions;

use App\Events\UserInvitedToQuiz;
use App\Models\Quiz;
use App\Models\User;
use Illuminate\Support\Collection;
Expand All @@ -13,12 +14,16 @@ class AssignToQuizAction
/**
* @param Collection<int> $userIds
*/
public function execute(Quiz $quiz, Collection $userIds): void
public function execute(Quiz $quiz, Collection $userIds, User $inviter): void
{
$assignedUsers = $quiz->assignedUsers()->get();
$users = User::query()->whereIn("id", $userIds)->get();

$users = $users->filter(fn(User $user) => !$assignedUsers->contains($user));
$quiz->assignedUsers()->attach($users);

foreach ($users as $user) {
event(new UserInvitedToQuiz($quiz, $user, $inviter));
}
}
}
24 changes: 24 additions & 0 deletions app/Events/UserInvitedToQuiz.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace App\Events;

use App\Models\Quiz;
use App\Models\User;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class UserInvitedToQuiz
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

public function __construct(
public Quiz $quiz,
public User $invitee,
public User $inviter,
) {}
}
10 changes: 1 addition & 9 deletions app/Http/Controllers/ContestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
namespace App\Http\Controllers;

use App\Http\Resources\QuizResource;
use App\Http\Resources\SchoolResource;
use App\Http\Resources\UserQuizResource;
use App\Models\Quiz;
use App\Models\School;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
Expand All @@ -18,13 +16,7 @@ class ContestController extends Controller
{
public function index(): Response
{
$schools = School::query()
->where("is_disabled", false)
->where("is_admin_school", false)
->orderBy("name")
->get();

return Inertia::render("Home", ["schools" => SchoolResource::collection($schools)]);
return Inertia::render("Home");
}

public function create(Request $request): RedirectResponse|Response
Expand Down
44 changes: 37 additions & 7 deletions app/Http/Controllers/InviteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
use App\Helpers\SortHelper;
use App\Http\Requests\InviteQuizRequest;
use App\Http\Resources\QuizResource;
use App\Http\Resources\SchoolResource;
use App\Http\Resources\UserResource;
use App\Models\Quiz;
use App\Models\School;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\RedirectResponse;
Expand All @@ -25,17 +23,25 @@ class InviteController extends Controller
public function index(Quiz $quiz, SortHelper $sort, Request $request): Response
{
$this->authorize("invite", $quiz);

$query = User::query()->role("user")->with("school")->whereNotNull("email_verified_at");
$query = $sort->sort($query, ["id"], ["name", "school"]);
$query = $this->sortByName($query, $sort);
$query = $this->sortBySchool($query, $sort);
$query = $this->filterByName($query, $request);
$query = $this->filterByMode($query, $request);
$query = $this->filterBySchool($query, $request);

$quizzes = Quiz::query()
->select("id", "title")
->whereNotNull("scheduled_at")
->where("scheduled_at", ">", now())
->whereNotNull("locked_at")
->get();

return Inertia::render("Admin/Invite", [
"users" => UserResource::collection($sort->paginate($query)),
"quiz" => QuizResource::make($quiz),
"schools" => SchoolResource::collection(School::all()),
"quizzes" => $quizzes,
"assigned" => $quiz->assignedUsers->pluck("id"),
]);
}
Expand All @@ -44,11 +50,11 @@ public function assign(Quiz $quiz, InviteQuizRequest $request, AssignToQuizActio
{
$this->authorize("invite", $quiz);

$assignAction->execute($quiz, collect($request->input("ids")));
$assignAction->execute($quiz, collect($request->input("ids")), $request->user());

return redirect()
->back()
->with("status", "Użytkownicy zostali przypisani do quizu.");
->with("status", "Użytkownicy zostali przypisani do testu. Za 15 minut zostaną o tym powiadomieni drogą mailową. Jeżeli w ciągu 15 minut anulujesz zaproszenie, e-mail nie zostanie wysłany.");
}

public function unassign(Quiz $quiz, InviteQuizRequest $request, UnassignFromQuizAction $unassignAction): RedirectResponse
Expand All @@ -59,7 +65,18 @@ public function unassign(Quiz $quiz, InviteQuizRequest $request, UnassignFromQui

return redirect()
->back()
->with("status", "Użytkownicy zostali wypisani z quizu.");
->with("status", "Użytkownicy zostali wypisani z testu.");
}

private function filterByMode(Builder $query, Request $request)
{
$mode = $request->query("mode", "user");

if ($mode === "school") {
return $this->filterBySchoolName($query, $request);
}

return $this->filterByName($query, $request);
}

private function filterByName(Builder $query, Request $request): Builder
Expand All @@ -74,6 +91,19 @@ private function filterByName(Builder $query, Request $request): Builder
return $query;
}

private function filterBySchoolName(Builder $query, Request $request): Builder
{
$searchName = $request->query("search");

if ($searchName) {
return $query->whereHas("school", function (Builder $schoolQuery) use ($searchName): void {
$schoolQuery->where("name", "ilike", "%$searchName%");
});
}

return $query;
}

private function filterBySchool(Builder $query, Request $request): Builder
{
$searchSchool = $request->query("schoolId");
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/QuizController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function createUserQuiz(CreateUserQuizAction $action, Request $request, Q

public function assign(AssignToQuizAction $action, Request $request, Quiz $quiz): RedirectResponse
{
$action->execute($quiz, collect([$request->user()->id]));
$action->execute($quiz, collect([$request->user()->id]), $request->user());

return redirect()
->back()
Expand Down
32 changes: 23 additions & 9 deletions app/Http/Controllers/SchoolsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
use App\Helpers\SortHelper;
use App\Http\Requests\SchoolRequest;
use App\Http\Resources\SchoolResource;
use App\Http\Resources\SchoolSearchResource;
use App\Jobs\FetchSchoolsJob;
use App\Models\School;
use Illuminate\Bus\Batch;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Cache;
use Inertia\Inertia;
Expand All @@ -29,16 +31,16 @@ class SchoolsController extends Controller
{
public function index(SortHelper $sorter, Request $request): Response
{
$query = School::query()->where("is_admin_school", false);
$query = $sorter->sort($query, ["id", "name", "regon", "updated_at", "created_at"], ["students", "address"]);
$query = $this->sortByStudents($query, $sorter);
$query = $this->sortByAddress($query, $sorter);
$query = $this->filterDisabledSchools($query, $request);
$query = $sorter->search($query, "name");
$schools = $this->searchQuery($sorter, $request);

return Inertia::render("Admin/SchoolsPanel", [
"schools" => SchoolResource::collection($sorter->paginate($query)),
]);
return Inertia::render("Admin/SchoolsPanel", ["schools" => SchoolResource::collection($schools)]);
}

public function search(SortHelper $sorter, Request $request): JsonResponse
{
$schools = $this->searchQuery($sorter, $request);

return SchoolSearchResource::collection($schools)->response();
}

public function store(SchoolRequest $request): RedirectResponse
Expand Down Expand Up @@ -134,6 +136,18 @@ protected function findBatch(): ?Batch
return Bus::findBatch($batchId);
}

private function searchQuery(SortHelper $sorter, Request $request): LengthAwarePaginator
{
$query = School::query()->where("is_admin_school", false);
$query = $sorter->sort($query, ["id", "name", "regon", "updated_at", "created_at"], ["students", "address"]);
$query = $this->sortByStudents($query, $sorter);
$query = $this->sortByAddress($query, $sorter);
$query = $this->filterDisabledSchools($query, $request);
$query = $sorter->search($query, "name");

return $sorter->paginate($query);
}

private function sortByStudents(Builder $query, SortHelper $sorter): Builder
{
[$field, $order] = $sorter->getSortParameters();
Expand Down
7 changes: 0 additions & 7 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

use App\Helpers\SortHelper;
use App\Http\Requests\UserRequest;
use App\Http\Resources\SchoolResource;
use App\Http\Resources\UserResource;
use App\Models\School;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\RedirectResponse;
Expand All @@ -21,10 +19,6 @@ class UserController extends Controller
public function index(SortHelper $sorter, Request $request): Response
{
$users = User::query()->role("user")->with("school");
$schools = School::query()
->where("is_admin_school", false)
->orderBy("name")
->get();

$query = $sorter->sort($users, ["id", "email", "updated_at", "created_at"], ["firstname", "school"]);
$query = $this->filterAnonymizedUsers($query, $request);
Expand All @@ -34,7 +28,6 @@ public function index(SortHelper $sorter, Request $request): Response

return Inertia::render("Admin/UsersPanel", [
"users" => UserResource::collection($query->paginate()),
"schools" => SchoolResource::collection($schools),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/Auth/ResetPasswordRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function authorize(): bool
public function rules(): array
{
return [
"token" => ["required"],
"token" => ["required", "max:255"],
"email" => ["required", "email", "max:255"],
"password" => ["required", "min:8", "max:255", "confirmed:password_confirmation"],
];
Expand Down
23 changes: 23 additions & 0 deletions app/Http/Resources/SchoolSearchResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class SchoolSearchResource extends JsonResource
{
/**
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
"id" => $this->id,
"name" => $this->name,
"city" => $this->city,
];
}
}
20 changes: 19 additions & 1 deletion app/Jobs/SendInviteJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\Middleware\SkipIfBatchCancelled;
use Illuminate\Queue\SerializesModels;

class SendInviteJob implements ShouldQueue
Expand All @@ -27,8 +28,25 @@ public function __construct(
protected Quiz $quiz,
) {}

public function middleware(): array
{
return [new SkipIfBatchCancelled()];
}

public function handle(): void
{
$this->user->notify(new InviteUserNotification($this->quiz));
if ($this->quiz->assignedUsers->contains("id", $this->user->id)) {
$this->user->notify(new InviteUserNotification($this->quiz));
}
}

public function getUser(): User
{
return $this->user;
}

public function getQuiz(): Quiz
{
return $this->quiz;
}
}
32 changes: 32 additions & 0 deletions app/Listeners/SendInvitedToQuizNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace App\Listeners;

use App\Events\UserInvitedToQuiz;
use App\Jobs\SendInviteJob;
use Carbon\Carbon;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Cache;

class SendInvitedToQuizNotification implements ShouldQueue
{
public function handle(UserInvitedToQuiz $event): void
{
$quiz = $event->quiz;
$busName = "send_invite-" . $quiz->id . "-" . $event->invitee->id;
$busId = Cache::get($busName);

if ($busId !== null) {
Bus::findBatch($busId)?->cancel();
}

$busId = Bus::batch([
(new SendInviteJob($event->invitee, $quiz))->delay(Carbon::now()->addMinutes(15)),
])->dispatch()->id;

Cache::set($busName, $busId);
}
}
1 change: 1 addition & 0 deletions app/Notifications/InviteUserNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function toMail(object $notifiable): MailMessage
->view("emails.auth.invite-user", [
"user" => $notifiable,
"quiz" => $this->quiz,
"url" => url("/dashboard"),
]);
}
}
Loading
Loading