This commit is contained in:
J. A. Messias 2024-10-01 10:42:43 -03:00
parent 479b76dc26
commit 014cdcac93
3 changed files with 48 additions and 24 deletions

View File

@ -71,28 +71,37 @@ class _BottomArrowLinkedLocalsComponentWidgetState
final List<dynamic> 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 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;
@ -182,12 +191,13 @@ class _BottomArrowLinkedLocalsComponentWidgetState
String message = FFLocalizations.of(context).getVariableText(
ptText:
'Local Bloqueado para Acesso, Entre em Contato com Administração',
enText: 'Location Blocked for Access, Contact Administration');
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 = [];

View File

@ -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<dynamic> locals = response.jsonBody['locais'] ?? [];
final List<dynamic> 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();

View File

@ -54,9 +54,14 @@ class _ReceptionPageWidgetState extends State<ReceptionPageWidget>
var response = await callback.call();
if (response.jsonBody['error'] == false) {
List<dynamic> locals = response.jsonBody['locais'] ?? [];
final List<dynamic> 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;