Skip to content

Commit

Permalink
Cancelled and queued registrations in admin screen (#428)
Browse files Browse the repository at this point in the history
Co-authored-by: Marijn Meuleman <marijnjmeuleman@gmail.com>
Co-authored-by: Jaap Aarts <jaap.aarts1@gmail.com>
Co-authored-by: Dirk Doesburg <dirk.doesburg@gmail.com>
  • Loading branch information
4 people authored Nov 15, 2023
1 parent a811825 commit c76a69c
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 102 deletions.
3 changes: 2 additions & 1 deletion lib/api/api_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,15 @@ abstract class ApiRepository {
/// total number of registrations that can be returned.
/// Use `search` to filter on name, `ordering` to order with values in
/// {'date', 'date_cancelled', 'queue_position', '-date', '-date_cancelled',
/// '-queue_position'}, and `cancelled` to filter on cancelled registrations.
/// '-queue_position'}, `cancelled` to filter on cancelled registrations, and `queued` to filter on queued registrations.
Future<ListResponse<AdminEventRegistration>> getAdminEventRegistrations({
required int pk,
int? limit,
int? offset,
String? search,
String? ordering,
bool? cancelled,
bool? queued,
});

/// Mark the user's registration for [Event] `pk` as present, using `token`.
Expand Down
2 changes: 2 additions & 0 deletions lib/api/concrexit_api_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ class ConcrexitApiRepository implements ApiRepository {
String? search,
String? ordering,
bool? cancelled,
bool? queued,
}) async {
assert(
ordering == null ||
Expand All @@ -439,6 +440,7 @@ class ConcrexitApiRepository implements ApiRepository {
if (ordering != null) 'ordering': ordering,
if (search != null) 'search': search,
if (cancelled != null) 'cancelled': cancelled.toString(),
if (queued != null) 'queued': queued.toString(),
},
);
final response = await _handleExceptions(() => _client.get(uri));
Expand Down
77 changes: 70 additions & 7 deletions lib/blocs/event_admin_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class EventAdminState extends Equatable {

/// These may be outdated when [isLoading] is true.
final List<AdminEventRegistration> registrations;
final List<AdminEventRegistration> cancelledRegistrations;
final List<AdminEventRegistration> queuedRegistrations;

final String? message;
final bool isLoading;
Expand All @@ -24,6 +26,8 @@ class EventAdminState extends Equatable {
const EventAdminState({
required this.event,
required this.registrations,
required this.cancelledRegistrations,
required this.queuedRegistrations,
required this.isLoading,
required this.message,
}) : assert(
Expand All @@ -32,33 +36,53 @@ class EventAdminState extends Equatable {
);

@override
List<Object?> get props => [event, registrations, message, isLoading];
List<Object?> get props => [
event,
registrations,
cancelledRegistrations,
queuedRegistrations,
message,
isLoading
];

EventAdminState copyWith({
AdminEvent? event,
List<AdminEventRegistration>? registrations,
List<AdminEventRegistration>? cancelledRegistrations,
List<AdminEventRegistration>? queuedRegistrations,
bool? isLoading,
String? message,
}) =>
EventAdminState(
event: event ?? this.event,
registrations: registrations ?? this.registrations,
cancelledRegistrations:
cancelledRegistrations ?? this.cancelledRegistrations,
queuedRegistrations: queuedRegistrations ?? this.queuedRegistrations,
isLoading: isLoading ?? this.isLoading,
message: message ?? this.message,
);

const EventAdminState.result({
required AdminEvent this.event,
required this.registrations,
}) : message = null,
const EventAdminState.result(
{required AdminEvent this.event,
required this.registrations,
required this.cancelledRegistrations,
required this.queuedRegistrations})
: message = null,
isLoading = false;

const EventAdminState.loading({this.event, required this.registrations})
const EventAdminState.loading(
{this.event,
required this.registrations,
required this.cancelledRegistrations,
required this.queuedRegistrations})
: message = null,
isLoading = true;

const EventAdminState.failure({required String this.message, this.event})
: registrations = const [],
cancelledRegistrations = const [],
queuedRegistrations = const [],
isLoading = false;
}

Expand All @@ -78,7 +102,10 @@ class EventAdminCubit extends Cubit<EventAdminState> {
EventAdminCubit(
this.api, {
required this.eventPk,
}) : super(const EventAdminState.loading(registrations: []));
}) : super(const EventAdminState.loading(
registrations: [],
cancelledRegistrations: [],
queuedRegistrations: []));

Future<void> load() async {
emit(state.copyWith(isLoading: true));
Expand All @@ -90,6 +117,21 @@ class EventAdminCubit extends Cubit<EventAdminState> {
search: query,
limit: 999999999,
cancelled: false,
queued: false,
);
final cancelledRegistrations = await api.getAdminEventRegistrations(
pk: eventPk,
search: query,
limit: 999999999,
cancelled: true,
ordering: '-date_cancelled',
);
final queuedRegistrations = await api.getAdminEventRegistrations(
pk: eventPk,
search: query,
limit: 999999999,
queued: true,
ordering: 'queue_position',
);

// Discard result if _searchQuery has
Expand All @@ -114,6 +156,8 @@ class EventAdminCubit extends Cubit<EventAdminState> {
emit(EventAdminState.result(
event: event,
registrations: registrations.results,
cancelledRegistrations: cancelledRegistrations.results,
queuedRegistrations: queuedRegistrations.results,
));
}
} on ApiException catch (exception) {
Expand All @@ -134,6 +178,21 @@ class EventAdminCubit extends Cubit<EventAdminState> {
search: query,
limit: 999999999,
cancelled: false,
queued: false,
);
final cancelledRegistrations = await api.getAdminEventRegistrations(
pk: eventPk,
search: query,
limit: 999999999,
cancelled: true,
ordering: '-date_cancelled',
);
final queuedRegistrations = await api.getAdminEventRegistrations(
pk: eventPk,
search: query,
limit: 999999999,
queued: true,
ordering: 'queue_position',
);

// Discard result if _searchQuery has
Expand All @@ -156,6 +215,8 @@ class EventAdminCubit extends Cubit<EventAdminState> {
emit(EventAdminState.result(
event: event,
registrations: registrations.results,
cancelledRegistrations: cancelledRegistrations.results,
queuedRegistrations: queuedRegistrations.results,
));
}
} on ApiException catch (exception) {
Expand All @@ -180,6 +241,8 @@ class EventAdminCubit extends Cubit<EventAdminState> {
emit(EventAdminState.loading(
event: state.event,
registrations: const [],
cancelledRegistrations: const [],
queuedRegistrations: const [],
));
} else {
_searchDebounceTimer = Timer(
Expand Down
4 changes: 4 additions & 0 deletions lib/models/event_registration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class AdminEventRegistration implements EventRegistration {
final bool present;
final int? queuePosition;
final DateTime date;
final DateTime? dateCancelled;
final Payment? payment;

bool get isInQueue => queuePosition != null;
Expand All @@ -89,6 +90,7 @@ class AdminEventRegistration implements EventRegistration {
this.present,
this.queuePosition,
this.date,
this.dateCancelled,
this.payment,
) : assert(
member != null || name != null,
Expand All @@ -103,6 +105,7 @@ class AdminEventRegistration implements EventRegistration {
newPresent,
queuePosition,
date,
dateCancelled,
payment,
);

Expand All @@ -114,6 +117,7 @@ class AdminEventRegistration implements EventRegistration {
present,
queuePosition,
date,
dateCancelled,
newPayment,
);

Expand Down
4 changes: 4 additions & 0 deletions lib/models/event_registration.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c76a69c

Please sign in to comment.