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

Add button to call fix iCal calendars cloud function to admin console #1625

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions console/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:flutter/material.dart';
import 'package:sharezone_console/activation_codes/activation_codes_page.dart';
import 'package:sharezone_console/pages/change_type_of_user.dart';
import 'package:sharezone_console/pages/feedbacks/feedbacks_page.dart';
import 'package:sharezone_console/pages/fix_ical_calendars.dart';

Future<void> openPage(BuildContext context, Widget widget) {
return Navigator.push(
Expand Down Expand Up @@ -48,6 +49,13 @@ class HomePage extends StatelessWidget {
openPage(context, FeedbacksPage());
},
),
ListTile(
leading: Icon(Icons.calendar_today),
title: const Text("Fix iCal Calendars"),
onTap: () {
openPage(context, FixICalCalendars());
},
),
],
),
);
Expand Down
107 changes: 107 additions & 0 deletions console/lib/pages/fix_ical_calendars.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright (c) 2024 Sharezone UG (haftungsbeschränkt)
// Licensed under the EUPL-1.2-or-later.
//
// You may obtain a copy of the Licence at:
// https://joinup.ec.europa.eu/software/page/eupl
//
// SPDX-License-Identifier: EUPL-1.2

import 'package:cloud_functions/cloud_functions.dart';
import 'package:flutter/material.dart';

class FixICalCalendars extends StatefulWidget {
const FixICalCalendars({super.key});

@override
State<FixICalCalendars> createState() => _FixICalCalendarsState();
}

class _FixICalCalendarsState extends State<FixICalCalendars> {
int? amountOfFixedCalendars;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Fix iCal Calendars"),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
width: 300,
child: Text(
'A cloud function that can be used to check if some iCal calendars are not in sync with the database. If they are not in sync, they will be fixed.',
textAlign: TextAlign.center,
),
),
const SizedBox(height: 12),
_Button(
(int amount) {
setState(() {
amountOfFixedCalendars = amount;
});
},
),
if (amountOfFixedCalendars != null)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text("Fixed $amountOfFixedCalendars calendars"),
),
],
),
),
);
}
}

class _Button extends StatefulWidget {
const _Button(this.amountOfFixedCalendars);

final ValueChanged<int> amountOfFixedCalendars;

@override
State<_Button> createState() => _ButtonState();
}

class _ButtonState extends State<_Button> {
bool isLoading = false;

@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: isLoading
? null
: () async {
setState(() {
isLoading = true;
});

try {
final cfs =
FirebaseFunctions.instanceFor(region: 'europe-west1');
final function = cfs.httpsCallable('fixICalCalendars');

final result = await function.call<Map<String, dynamic>>();
widget.amountOfFixedCalendars(
result.data['amountOfFixedCalendars']);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Error: $e'),
),
);
} finally {
setState(() {
isLoading = false;
});
}
},
child: Text(
isLoading ? "Loading..." : "Fix",
style: TextStyle(color: Colors.white),
),
);
}
}
Loading