refactor(ui): Move all pop up dialogs into general utils function
To not import get_it everywhere and encapsulate all the related dirt into utils.pull/140/head
parent
6eb49fa8f1
commit
cdc47ecdb3
|
@ -31,7 +31,8 @@
|
||||||
"remove": "Remove",
|
"remove": "Remove",
|
||||||
"apply": "Apply",
|
"apply": "Apply",
|
||||||
"done": "Done",
|
"done": "Done",
|
||||||
"continue": "Continue"
|
"continue": "Continue",
|
||||||
|
"alert": "Alert"
|
||||||
},
|
},
|
||||||
"more_page": {
|
"more_page": {
|
||||||
"configuration_wizard": "Setup wizard",
|
"configuration_wizard": "Setup wizard",
|
||||||
|
|
|
@ -31,7 +31,8 @@
|
||||||
"remove": "Удалить",
|
"remove": "Удалить",
|
||||||
"apply": "Применить",
|
"apply": "Применить",
|
||||||
"done": "Готово",
|
"done": "Готово",
|
||||||
"continue": "Продолжить"
|
"continue": "Продолжить",
|
||||||
|
"alert": "Уведомление"
|
||||||
},
|
},
|
||||||
"more_page": {
|
"more_page": {
|
||||||
"configuration_wizard": "Мастер настройки",
|
"configuration_wizard": "Мастер настройки",
|
||||||
|
|
|
@ -27,8 +27,7 @@ import 'package:selfprivacy/logic/models/json/dns_records.dart';
|
||||||
import 'package:selfprivacy/logic/models/message.dart';
|
import 'package:selfprivacy/logic/models/message.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_basic_info.dart';
|
import 'package:selfprivacy/logic/models/server_basic_info.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_type.dart';
|
import 'package:selfprivacy/logic/models/server_type.dart';
|
||||||
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
import 'package:selfprivacy/ui/helpers/modals.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
|
|
||||||
import 'package:selfprivacy/utils/network_utils.dart';
|
import 'package:selfprivacy/utils/network_utils.dart';
|
||||||
|
|
||||||
class IpNotFoundException implements Exception {
|
class IpNotFoundException implements Exception {
|
||||||
|
@ -262,16 +261,11 @@ class ServerInstallationRepository {
|
||||||
onSuccess(serverDetails);
|
onSuccess(serverDetails);
|
||||||
} on DioError catch (e) {
|
} on DioError catch (e) {
|
||||||
if (e.response!.data['error']['code'] == 'uniqueness_error') {
|
if (e.response!.data['error']['code'] == 'uniqueness_error') {
|
||||||
final NavigationService nav = getIt.get<NavigationService>();
|
showPopUpAlert(
|
||||||
nav.showPopUpDialog(
|
alertTitle: 'modals.already_exists'.tr(),
|
||||||
BrandAlert(
|
description: 'modals.destroy_server'.tr(),
|
||||||
title: 'modals.already_exists'.tr(),
|
actionButtonTitle: 'modals.yes'.tr(),
|
||||||
contentText: 'modals.destroy_server'.tr(),
|
actionButtonOnPressed: () async {
|
||||||
actions: [
|
|
||||||
ActionButton(
|
|
||||||
text: 'basis.delete'.tr(),
|
|
||||||
isRed: true,
|
|
||||||
onPressed: () async {
|
|
||||||
await api.deleteServer(
|
await api.deleteServer(
|
||||||
domainName: domainName,
|
domainName: domainName,
|
||||||
);
|
);
|
||||||
|
@ -295,25 +289,14 @@ class ServerInstallationRepository {
|
||||||
await saveServerDetails(serverDetails);
|
await saveServerDetails(serverDetails);
|
||||||
onSuccess(serverDetails);
|
onSuccess(serverDetails);
|
||||||
},
|
},
|
||||||
),
|
cancelButtonOnPressed: onCancel,
|
||||||
ActionButton(
|
|
||||||
text: 'basis.cancel'.tr(),
|
|
||||||
onPressed: onCancel,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
final NavigationService nav = getIt.get<NavigationService>();
|
showPopUpAlert(
|
||||||
nav.showPopUpDialog(
|
alertTitle: 'modals.unexpected_error'.tr(),
|
||||||
BrandAlert(
|
description: 'modals.try_again'.tr(),
|
||||||
title: 'modals.unexpected_error'.tr(),
|
actionButtonTitle: 'modals.yes'.tr(),
|
||||||
contentText: 'modals.try_again'.tr(),
|
actionButtonOnPressed: () async {
|
||||||
actions: [
|
|
||||||
ActionButton(
|
|
||||||
text: 'modals.yes'.tr(),
|
|
||||||
isRed: true,
|
|
||||||
onPressed: () async {
|
|
||||||
ServerHostingDetails? serverDetails;
|
ServerHostingDetails? serverDetails;
|
||||||
try {
|
try {
|
||||||
serverDetails = await api.createServer(
|
serverDetails = await api.createServer(
|
||||||
|
@ -333,13 +316,7 @@ class ServerInstallationRepository {
|
||||||
await saveServerDetails(serverDetails);
|
await saveServerDetails(serverDetails);
|
||||||
onSuccess(serverDetails);
|
onSuccess(serverDetails);
|
||||||
},
|
},
|
||||||
),
|
cancelButtonOnPressed: onCancel,
|
||||||
ActionButton(
|
|
||||||
text: 'basis.cancel'.tr(),
|
|
||||||
onPressed: onCancel,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -366,31 +343,19 @@ class ServerInstallationRepository {
|
||||||
domain: domain,
|
domain: domain,
|
||||||
);
|
);
|
||||||
} on DioError catch (e) {
|
} on DioError catch (e) {
|
||||||
final NavigationService nav = getIt.get<NavigationService>();
|
showPopUpAlert(
|
||||||
nav.showPopUpDialog(
|
alertTitle: e.response!.data['errors'][0]['code'] == 1038
|
||||||
BrandAlert(
|
|
||||||
title: e.response!.data['errors'][0]['code'] == 1038
|
|
||||||
? 'modals.you_cant_use_this_api'.tr()
|
? 'modals.you_cant_use_this_api'.tr()
|
||||||
: 'domain.error'.tr(),
|
: 'domain.error'.tr(),
|
||||||
contentText: 'modals.delete_server_volume'.tr(),
|
description: 'modals.delete_server_volume'.tr(),
|
||||||
actions: [
|
cancelButtonOnPressed: onCancel,
|
||||||
ActionButton(
|
actionButtonTitle: 'basis.delete'.tr(),
|
||||||
text: 'basis.delete'.tr(),
|
actionButtonOnPressed: () async {
|
||||||
isRed: true,
|
|
||||||
onPressed: () async {
|
|
||||||
await serverApi.deleteServer(
|
await serverApi.deleteServer(
|
||||||
domainName: domain.domainName,
|
domainName: domain.domainName,
|
||||||
);
|
);
|
||||||
|
|
||||||
onCancel();
|
onCancel();
|
||||||
},
|
},
|
||||||
),
|
|
||||||
ActionButton(
|
|
||||||
text: 'basis.cancel'.tr(),
|
|
||||||
onPressed: onCancel,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,18 +2,16 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:selfprivacy/config/brand_theme.dart';
|
import 'package:selfprivacy/config/brand_theme.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
|
||||||
import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/server_jobs/server_jobs_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/server_jobs/server_jobs_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/json/server_job.dart';
|
import 'package:selfprivacy/logic/models/json/server_job.dart';
|
||||||
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
|
||||||
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
|
|
||||||
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_cards/brand_cards.dart';
|
import 'package:selfprivacy/ui/components/brand_cards/brand_cards.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_loader/brand_loader.dart';
|
import 'package:selfprivacy/ui/components/brand_loader/brand_loader.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
|
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
|
||||||
import 'package:selfprivacy/ui/components/jobs_content/server_job_card.dart';
|
import 'package:selfprivacy/ui/components/jobs_content/server_job_card.dart';
|
||||||
|
import 'package:selfprivacy/ui/helpers/modals.dart';
|
||||||
|
|
||||||
class JobsContent extends StatelessWidget {
|
class JobsContent extends StatelessWidget {
|
||||||
const JobsContent({super.key});
|
const JobsContent({super.key});
|
||||||
|
@ -47,26 +45,16 @@ class JobsContent extends StatelessWidget {
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
BrandButton.text(
|
BrandButton.text(
|
||||||
onPressed: () {
|
|
||||||
final NavigationService nav = getIt<NavigationService>();
|
|
||||||
nav.showPopUpDialog(
|
|
||||||
BrandAlert(
|
|
||||||
title: 'jobs.reboot_server'.tr(),
|
title: 'jobs.reboot_server'.tr(),
|
||||||
contentText: 'modals.are_you_sure'.tr(),
|
onPressed: () {
|
||||||
actions: [
|
showPopUpAlert(
|
||||||
ActionButton(
|
alertTitle: 'jobs.reboot_server'.tr(),
|
||||||
text: 'basis.cancel'.tr(),
|
description: 'modals.are_you_sure'.tr(),
|
||||||
),
|
actionButtonTitle: 'modals.reboot'.tr(),
|
||||||
ActionButton(
|
actionButtonOnPressed: () =>
|
||||||
onPressed: () =>
|
|
||||||
{context.read<JobsCubit>().rebootServer()},
|
{context.read<JobsCubit>().rebootServer()},
|
||||||
text: 'modals.reboot'.tr(),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
title: 'jobs.reboot_server'.tr(),
|
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
|
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
|
||||||
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
|
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
||||||
|
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
|
||||||
|
|
||||||
Future<T?> showBrandBottomSheet<T>({
|
Future<T?> showBrandBottomSheet<T>({
|
||||||
required final BuildContext context,
|
required final BuildContext context,
|
||||||
|
@ -12,3 +16,30 @@ Future<T?> showBrandBottomSheet<T>({
|
||||||
shadow: const BoxShadow(color: Colors.transparent),
|
shadow: const BoxShadow(color: Colors.transparent),
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
void showPopUpAlert({
|
||||||
|
required final String description,
|
||||||
|
required final String actionButtonTitle,
|
||||||
|
required final void Function() actionButtonOnPressed,
|
||||||
|
final void Function()? cancelButtonOnPressed,
|
||||||
|
final String? alertTitle,
|
||||||
|
final String? cancelButtonTitle,
|
||||||
|
}) {
|
||||||
|
getIt.get<NavigationService>().showPopUpDialog(
|
||||||
|
BrandAlert(
|
||||||
|
title: alertTitle ?? 'basis.alert'.tr(),
|
||||||
|
contentText: description,
|
||||||
|
actions: [
|
||||||
|
ActionButton(
|
||||||
|
text: actionButtonTitle,
|
||||||
|
isRed: true,
|
||||||
|
onPressed: actionButtonOnPressed,
|
||||||
|
),
|
||||||
|
ActionButton(
|
||||||
|
text: cancelButtonTitle ?? 'basis.cancel'.tr(),
|
||||||
|
onPressed: cancelButtonOnPressed,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
|
||||||
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/backups/backups_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/backups/backups_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/json/backup.dart';
|
import 'package:selfprivacy/logic/models/json/backup.dart';
|
||||||
import 'package:selfprivacy/logic/models/state_types.dart';
|
import 'package:selfprivacy/logic/models/state_types.dart';
|
||||||
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
|
||||||
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
|
|
||||||
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_cards/outlined_card.dart';
|
import 'package:selfprivacy/ui/components/brand_cards/outlined_card.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_hero_screen/brand_hero_screen.dart';
|
import 'package:selfprivacy/ui/components/brand_hero_screen/brand_hero_screen.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
|
import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
|
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
|
||||||
|
import 'package:selfprivacy/ui/helpers/modals.dart';
|
||||||
|
|
||||||
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||||
|
|
||||||
|
@ -157,28 +155,17 @@ class _BackupDetailsState extends State<BackupDetails>
|
||||||
onTap: preventActions
|
onTap: preventActions
|
||||||
? null
|
? null
|
||||||
: () {
|
: () {
|
||||||
final NavigationService nav =
|
showPopUpAlert(
|
||||||
getIt<NavigationService>();
|
alertTitle: 'backup.restoring'.tr(),
|
||||||
nav.showPopUpDialog(
|
description: 'backup.restore_alert'.tr(
|
||||||
BrandAlert(
|
|
||||||
title: 'backup.restoring'.tr(),
|
|
||||||
contentText: 'backup.restore_alert'.tr(
|
|
||||||
args: [backup.time.toString()],
|
args: [backup.time.toString()],
|
||||||
),
|
),
|
||||||
actions: [
|
actionButtonTitle: 'modals.yes'.tr(),
|
||||||
ActionButton(
|
actionButtonOnPressed: () => {
|
||||||
text: 'basis.cancel'.tr(),
|
|
||||||
),
|
|
||||||
ActionButton(
|
|
||||||
onPressed: () => {
|
|
||||||
context
|
context
|
||||||
.read<BackupsCubit>()
|
.read<BackupsCubit>()
|
||||||
.restoreBackup(backup.id)
|
.restoreBackup(backup.id)
|
||||||
},
|
},
|
||||||
text: 'modals.yes'.tr(),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
title: Text(
|
title: Text(
|
||||||
|
|
Loading…
Reference in New Issue