From 014cdcac933d2741908b46d2891c1cb67637fa96 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Tue, 1 Oct 2024 10:42:43 -0300 Subject: [PATCH] WIP --- ..._arrow_linked_locals_component_widget.dart | 34 ++++++++++++------- .../local_profile_component_widget.dart | 29 ++++++++++------ .../reception_page/reception_page_widget.dart | 9 +++-- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart b/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart index 21d64ef6..6c498e52 100644 --- a/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart +++ b/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart @@ -71,28 +71,37 @@ class _BottomArrowLinkedLocalsComponentWidgetState final List locals = response.jsonBody['locais'] ?? []; - if (locals.isNotEmpty) { + final bool isEmpty = locals.isEmpty; + final bool isUnique = locals.length == 1; + final bool isActive = locals[0]['CLU_STATUS'] == 'A'; + final bool isBlocked = locals[0]['CLU_STATUS'] == 'B'; + final bool isEnabled = isUnique && isActive; + final bool isDisabled = isUnique && isBlocked; + + if (!isEmpty) { setState(() { _localsWrap.addAll(locals); _hasData = true; _loading = false; }); - // Verifica se há apenas um local e se o status é 'A' - if (locals.length == 1 && locals[0]['CLU_STATUS'] == 'A') { + if (isDisabled) { + context.go('/receptionPage'); + return response; + } + if (isEnabled) { final local = locals[0]; StorageUtil().cliName = local['CLI_NOME']; StorageUtil().cliUUID = local['CLI_ID']; StorageUtil().ownerUUID = local['CLU_OWNER_ID']; context.pop(); + return response; } return response; } - _showNoMoreDataSnackBar(context); - setState(() { _hasData = false; _loading = false; @@ -180,14 +189,15 @@ class _BottomArrowLinkedLocalsComponentWidgetState context.pop(); } else if (local['CLU_STATUS'] == 'B') { String message = FFLocalizations.of(context).getVariableText( - ptText: - 'Local Bloqueado para Acesso, Entre em Contato com Administração', - enText: 'Location Blocked for Access, Contact Administration'); + ptText: + 'Local Bloqueado para Acesso, Entre em Contato com Administração', + enText: 'Location Blocked for Access, Contact Administration', + ); - if (local['CLU_BLK_MESSAGE'] != null && - local['CLU_BLK_MESSAGE'] != '') { - message = local['CLU_BLK_MESSAGE']; - } + // if (local['CLU_BLK_MESSAGE'] != null && + // local['CLU_BLK_MESSAGE'] != '') { + // message = local['CLU_BLK_MESSAGE']; + // } DialogUtil.warning(context, message); _localsWrap = []; diff --git a/lib/components/organism_components/local_profile_component/local_profile_component_widget.dart b/lib/components/organism_components/local_profile_component/local_profile_component_widget.dart index 4a0966fd..d6f5fb82 100644 --- a/lib/components/organism_components/local_profile_component/local_profile_component_widget.dart +++ b/lib/components/organism_components/local_profile_component/local_profile_component_widget.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/storage_util.dart'; @@ -40,9 +41,9 @@ class _LocalProfileComponentWidgetState _model.setOnUpdate(onUpdate: () => setState(() {})); _model.setStateCallback = () => safeSetState(() {}); - () async { + WidgetsBinding.instance.addPostFrameCallback((_) async { await processLocals(); - }(); + }); } @override @@ -59,7 +60,6 @@ class _LocalProfileComponentWidgetState var response = await callback.call(); final error = response.jsonBody['error']; - // final errorMsg = response.jsonBody['error_msg']; if (error == false) { final bool whatsapp = response.jsonBody['whatsapp'] ?? false; @@ -95,16 +95,25 @@ class _LocalProfileComponentWidgetState try { final GetLocalsCall callback = PhpGroup.getLocalsCall; - final cliUUID = StorageUtil().cliUUID; - final cliName = StorageUtil().cliName; - var response = await callback.call(); + final ApiCallResponse response = await callback.call(); - List locals = response.jsonBody['locais'] ?? []; + final List locals = response.jsonBody['locais'] + .where((local) => local['CLU_STATUS']) + .toList() ?? + []; - final activeLocals = - locals.where((local) => local['CLU_STATUS'] == 'A').toList(); + final bool isEnable = locals.any((local) => local['CLU_STATUS'] == 'A'); + final bool isUnique = locals.length == 1; + final bool isBlocked = locals[0]['CLU_STATUS'] == 'B'; + final bool isDisabled = isUnique && isBlocked; + final bool isSelected = + StorageUtil().cliUUID.isNotEmpty && StorageUtil().cliName.isNotEmpty; - if (activeLocals.isEmpty || cliUUID.isEmpty || cliName.isEmpty) { + if (isDisabled) { + context.go('/welcomePage'); + } else if (isEnable) { + await showModalSelectLocal(); + } else if (!isSelected) { await showModalSelectLocal(); } else { await processData(); diff --git a/lib/pages/reception_page/reception_page_widget.dart b/lib/pages/reception_page/reception_page_widget.dart index 7de37ed3..f768032c 100644 --- a/lib/pages/reception_page/reception_page_widget.dart +++ b/lib/pages/reception_page/reception_page_widget.dart @@ -54,9 +54,14 @@ class _ReceptionPageWidgetState extends State var response = await callback.call(); if (response.jsonBody['error'] == false) { - List locals = response.jsonBody['locais'] ?? []; + final List locals = response.jsonBody['locais'] ?? []; + final bool isEmpty = locals.isEmpty; + final bool isActive = locals + .where((local) => local['CLU_STATUS'] == 'A') + .toList() + .isNotEmpty; - if (locals.isNotEmpty) { + if (!isEmpty && isActive) { StorageUtil().haveLocal = true; StorageUtil().isLogged = true; await WidgetsBinding.instance.endOfFrame;