-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add button to call fix iCal calendars cloud function to admin console (…
…#1625) ![image](https://github.com/SharezoneApp/sharezone-app/assets/24459435/f17a2b7b-35cd-4a89-9d1e-e4d361d10c1a)
- Loading branch information
1 parent
96e7836
commit dc62d0e
Showing
2 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
); | ||
} | ||
} |