Skip to content

Commit

Permalink
Merge pull request #128 from canopas/Mayank/implement-tournament-deta…
Browse files Browse the repository at this point in the history
…il-members

Implement tournament detail members
  • Loading branch information
cp-mayank authored Oct 30, 2024
2 parents 83d868a + ec39bbd commit bdd2d09
Show file tree
Hide file tree
Showing 9 changed files with 699 additions and 13 deletions.
41 changes: 41 additions & 0 deletions data/lib/service/tournament/tournament_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,45 @@ class TournamentService {
throw AppError.fromError(error, stack);
}
}

Future<void> updateTournamentMembers(
String tournamentId,
List<TournamentMember> members,
) async {
try {
await _tournamentCollection.doc(tournamentId).update({
FireStoreConst.members: members.map((e) => e.toJson()).toList(),
});
} catch (error, stack) {
throw AppError.fromError(error, stack);
}
}

Future<void> removeTournamentMember(
String tournamentId,
TournamentMember member,
) async {
try {
await _tournamentCollection.doc(tournamentId).update({
FireStoreConst.members: FieldValue.arrayRemove([member.toJson()]),
});
} catch (error, stack) {
throw AppError.fromError(error, stack);
}
}

Future<void> changeTournamentOwner(
String tournamentId,
String? newOwnerId,
List<TournamentMember> members,
) async {
try {
await _tournamentCollection.doc(tournamentId).update({
FireStoreConst.createdBy: newOwnerId,
FireStoreConst.members: members.map((e) => e.toJson()).toList(),
});
} catch (error, stack) {
throw AppError.fromError(error, stack);
}
}
}
18 changes: 13 additions & 5 deletions khelo/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
"common_view_all": "View all",
"common_today": "Today",
"common_tomorrow": "Tomorrow",
"common_owner": "Owner",
"common_make_admin": "Make admin",
"common_remove_admin": "Remove admin",
"common_transfer_ownership": "Transfer ownership",
"common_obscure_phone_number_text": "{countryCode} ***** ***{lastDigits}",
"@common_obscure_phone_number_text": {
"description": "+{countryCode} ***** ***{lastDigits}",
Expand Down Expand Up @@ -253,6 +257,15 @@
"tournament_detail_stats_avg_title": "Avg",
"tournament_detail_stats_runs_title": "Runs",

"tournament_members_empty_title": "No members yet!",
"tournament_members_empty_description": "Tap the + button to add members and start managing your tournament effectively!",
"tournament_members_search_member_empty_title": "Assign Tournament Role",
"tournament_members_search_member_empty_description": "Search for a user to assign a management role. This role will empower them to help organize and lead the tournament effectively.",
"tournament_members_remove_self": "Remove self",
"tournament_members_make_organizer": "Make organizer",
"tournament_members_remove_member": "Remove member",
"tournament_members_transfer_ownership_description": "Search for a user to transfer tournament ownership. This grants them full management control. Choose someone who can effectively lead the tournament.",

"@_TOURNAMENT_TYPE":{
},
"tournament_type_knock_out": "Knockout",
Expand Down Expand Up @@ -430,19 +443,14 @@
"team_detail_empty_stat_description_text": "The players are warming up! Stay tuned for exciting stats as the team progresses.",
"team_detail_add_members_title": "Add members",
"team_detail_add_match_title": "Add match",
"team_detail_make_admin": "Make admin",
"team_detail_remove_admin": "Remove admin",
"team_detail_use_qr_description": "Use your phone camera or a QR code app to scan the code above and easily add the team to the tournament",
"make_admin_selection_error": "Can't select deactivated user as admin",
"team_detail_make_admin_screen_title": "Make Admin",
"team_detail_admin": "{count, plural, =0{{count} admins} =1{{count} admin} other{{count} admins}}",
"@team_detail_admin": {
"placeholders": {
"count": {}
}
},
"team_detail_make_admin_owner_title": "Owner",
"team_detail_transfer_ownership_title": "Transfer ownership",
"team_detail_remove_ownership_title": "Remove ownership",
"team_detail_transfer_ownership_description": "Search for a user to transfer team ownership. This grants them full management control. Choose someone who can effectively lead the team.",
"team_detail_match_tab_title": "Match",
Expand Down
14 changes: 14 additions & 0 deletions khelo/lib/ui/app_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import 'package:khelo/ui/flow/team/detail/team_detail_screen.dart';
import 'package:khelo/ui/flow/team/scanner/scanner_screen.dart';
import 'package:khelo/ui/flow/team/search_team/search_team_screen.dart';
import 'package:khelo/ui/flow/tournament/add/add_tournament_screen.dart';
import 'package:khelo/ui/flow/tournament/detail/members/tournament_detail_members_screen.dart';
import 'package:khelo/ui/flow/tournament/team_selection/team_selection_screen.dart';

import 'flow/home/view_all/home_view_all_screen.dart';
Expand Down Expand Up @@ -61,6 +62,7 @@ class AppRoute {
static const pathAddTournament = "/add-tournament";
static const pathTeamSelection = "/team-selection";
static const pathTournamentDetail = "/tournament-detail";
static const pathMemberSelection = "/member-selection";

final String path;
final String? name;
Expand Down Expand Up @@ -183,6 +185,14 @@ class AppRoute {
builder: (_) => TeamSelectionScreen(selectedTeams: selectedTeams),
);

static AppRoute memberSelection({required TournamentModel tournament}) =>
AppRoute(
pathMemberSelection,
builder: (_) => TournamentDetailMembersScreen(
tournament: tournament,
),
);

static AppRoute tournamentDetail({required String tournamentId}) => AppRoute(
pathTournamentDetail,
builder: (_) => TournamentDetailScreen(tournamentId: tournamentId),
Expand Down Expand Up @@ -350,6 +360,10 @@ class AppRoute {
path: pathTeamSelection,
builder: (context, state) => state.widget(context),
),
GoRoute(
path: pathMemberSelection,
builder: (context, state) => state.widget(context),
),
GoRoute(
path: pathTournamentDetail,
builder: (context, state) => state.widget(context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class _MakeAdminScreenState extends ConsumerState<MakeTeamAdminScreen> {
_observeActionError();
final state = ref.watch(makeTeamAdminStateProvider);
return AppPage(
title: context.l10n.team_detail_make_admin_screen_title,
title: context.l10n.common_make_admin,
actions: [
actionButton(context,
onPressed: state.isButtonEnabled ? notifier.onSave : null,
Expand Down Expand Up @@ -123,7 +123,7 @@ class _MakeAdminScreenState extends ConsumerState<MakeTeamAdminScreen> {
? context
.l10n.team_detail_remove_ownership_title
: context
.l10n.team_detail_transfer_ownership_title,
.l10n.common_transfer_ownership,
onTap: () async {
context.pop();
if (notifier.team.created_by_user.id !=
Expand All @@ -136,7 +136,7 @@ class _MakeAdminScreenState extends ConsumerState<MakeTeamAdminScreen> {
await SearchUserBottomSheet.show<UserModel>(
context,
emptyScreenTitle: context
.l10n.team_detail_transfer_ownership_title,
.l10n.common_transfer_ownership,
emptyScreenDescription: context.l10n
.team_detail_transfer_ownership_description,
);
Expand All @@ -151,8 +151,8 @@ class _MakeAdminScreenState extends ConsumerState<MakeTeamAdminScreen> {
BottomSheetAction(
title: state.selectedPlayerIds
.contains(state.owner.id)
? context.l10n.team_detail_remove_admin
: context.l10n.team_detail_make_admin,
? context.l10n.common_remove_admin
: context.l10n.common_make_admin,
onTap: () {
context.pop();
notifier.selectAdmin(state.owner);
Expand All @@ -164,7 +164,7 @@ class _MakeAdminScreenState extends ConsumerState<MakeTeamAdminScreen> {
}
},
trailing: Text(
context.l10n.team_detail_make_admin_owner_title,
context.l10n.common_owner,
style: AppTextStyle.body2
.copyWith(color: context.colorScheme.primary)),
)
Expand Down
2 changes: 1 addition & 1 deletion khelo/lib/ui/flow/team/detail/team_detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class _TeamDetailScreenState extends ConsumerState<TeamDetailScreen> {
),
if (state.team?.players.isNotEmpty ?? false)
BottomSheetAction(
title: context.l10n.team_detail_make_admin,
title: context.l10n.common_make_admin,
child: Text(context.l10n.team_detail_admin(state.team!.players
.where((element) => element.role == TeamPlayerRole.admin)
.toList()
Expand Down
Loading

0 comments on commit bdd2d09

Please sign in to comment.