diff --git a/apps/mobile/packages/domain/lib/src/entities/profile/emergency_contact.dart b/apps/mobile/packages/domain/lib/src/entities/profile/emergency_contact.dart index 0ca41349..ed3d438d 100644 --- a/apps/mobile/packages/domain/lib/src/entities/profile/emergency_contact.dart +++ b/apps/mobile/packages/domain/lib/src/entities/profile/emergency_contact.dart @@ -56,7 +56,7 @@ class EmergencyContact extends Equatable { /// Converts a string value to a [RelationshipType]. static RelationshipType stringToRelationshipType(String? value) { if (value != null) { - final strVal = value.toUpperCase(); + final String strVal = value.toUpperCase(); switch (strVal) { case 'FAMILY': return RelationshipType.family; diff --git a/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/domain/extensions/emergency_contact_extensions.dart b/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/domain/extensions/emergency_contact_extensions.dart deleted file mode 100644 index dce5ba36..00000000 --- a/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/domain/extensions/emergency_contact_extensions.dart +++ /dev/null @@ -1,30 +0,0 @@ -import 'package:krow_domain/krow_domain.dart'; - -/// Extensions for [EmergencyContact] to support UI operations. -extension EmergencyContactExtensions on EmergencyContact { - /// returns a copy of this [EmergencyContact] with the given fields replaced. - EmergencyContact copyWith({ - String? id, - String? name, - String? phone, - RelationshipType? relationship, - }) { - return EmergencyContact( - id: id ?? this.id, - name: name ?? this.name, - phone: phone ?? this.phone, - relationship: relationship ?? this.relationship, - ); - } - - /// Returns an empty [EmergencyContact]. - static EmergencyContact empty() { - return const EmergencyContact( - id: '', - name: '', - phone: '', - relationship: RelationshipType.family, - ); - } -} - diff --git a/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/presentation/blocs/emergency_contact_bloc.dart b/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/presentation/blocs/emergency_contact_bloc.dart index ae126661..269563a4 100644 --- a/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/presentation/blocs/emergency_contact_bloc.dart +++ b/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/presentation/blocs/emergency_contact_bloc.dart @@ -91,7 +91,10 @@ class EmergencyContactBloc on(_onRemoved); on(_onUpdated); on(_onSaved); + + add(EmergencyContactsLoaded()); } + Future _onLoaded( EmergencyContactsLoaded event, diff --git a/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/presentation/pages/emergency_contact_screen.dart b/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/presentation/pages/emergency_contact_screen.dart index 3d53be99..def60251 100644 --- a/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/presentation/pages/emergency_contact_screen.dart +++ b/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/presentation/pages/emergency_contact_screen.dart @@ -17,19 +17,6 @@ import '../widgets/emergency_contact_save_button.dart'; class EmergencyContactScreen extends StatelessWidget { const EmergencyContactScreen({super.key}); - @override - Widget build(BuildContext context) { - return BlocProvider( - create: (_) => - Modular.get()..add(EmergencyContactsLoaded()), - child: const _EmergencyContactView(), - ); - } -} - -class _EmergencyContactView extends StatelessWidget { - const _EmergencyContactView(); - @override Widget build(BuildContext context) { return Scaffold( @@ -48,44 +35,47 @@ class _EmergencyContactView extends StatelessWidget { child: Container(color: UiColors.border, height: 1.0), ), ), - body: BlocConsumer( - listener: (context, state) { - if (state.status == EmergencyContactStatus.failure) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(state.errorMessage ?? 'An error occurred')), - ); - } - }, - builder: (context, state) { - if (state.status == EmergencyContactStatus.loading) { - return const Center(child: CircularProgressIndicator()); - } - return Column( - children: [ - Expanded( - child: SingleChildScrollView( - padding: EdgeInsets.all(UiConstants.space6), - child: Column( - children: [ - const EmergencyContactInfoBanner(), - SizedBox(height: UiConstants.space6), - ...state.contacts.asMap().entries.map( - (entry) => EmergencyContactFormItem( - index: entry.key, - contact: entry.value, - totalContacts: state.contacts.length, + body: BlocProvider( + create: (context) => Modular.get(), + child: BlocConsumer( + listener: (context, state) { + if (state.status == EmergencyContactStatus.failure) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text(state.errorMessage ?? 'An error occurred')), + ); + } + }, + builder: (context, state) { + if (state.status == EmergencyContactStatus.loading) { + return const Center(child: CircularProgressIndicator()); + } + return Column( + children: [ + Expanded( + child: SingleChildScrollView( + padding: EdgeInsets.all(UiConstants.space6), + child: Column( + children: [ + const EmergencyContactInfoBanner(), + SizedBox(height: UiConstants.space6), + ...state.contacts.asMap().entries.map( + (entry) => EmergencyContactFormItem( + index: entry.key, + contact: entry.value, + totalContacts: state.contacts.length, + ), ), - ), - const EmergencyContactAddButton(), - SizedBox(height: UiConstants.space16), - ], + const EmergencyContactAddButton(), + SizedBox(height: UiConstants.space16), + ], + ), ), ), - ), - EmergencyContactSaveButton(state: state), - ], - ); - }, + EmergencyContactSaveButton(state: state), + ], + ); + }, + ), ), ); } diff --git a/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/presentation/widgets/emergency_contact_save_button.dart b/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/presentation/widgets/emergency_contact_save_button.dart index 28c4db1a..0b5ea1d7 100644 --- a/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/presentation/widgets/emergency_contact_save_button.dart +++ b/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/presentation/widgets/emergency_contact_save_button.dart @@ -17,39 +17,26 @@ class EmergencyContactSaveButton extends StatelessWidget { border: Border(top: BorderSide(color: UiColors.border)), ), child: SafeArea( - child: SizedBox( - width: double.infinity, - child: ElevatedButton( - onPressed: state.isValid - ? () => context - .read() - .add(EmergencyContactsSaved()) - : null, - style: ElevatedButton.styleFrom( - backgroundColor: UiColors.primary, - foregroundColor: UiColors.primaryForeground, - disabledBackgroundColor: UiColors.textPlaceholder, - padding: EdgeInsets.symmetric(vertical: UiConstants.space4), - shape: RoundedRectangleBorder( - borderRadius: UiConstants.radiusFull, - ), - elevation: 0, - ), - child: state.status == EmergencyContactStatus.saving - ? SizedBox( - height: 20.0, - width: 20.0, - child: CircularProgressIndicator( - strokeWidth: 2, - valueColor: - AlwaysStoppedAnimation(UiColors.primaryForeground), - ), - ) - : Text( - 'Save & Continue', - style: UiTypography.title2b, + child: UiButton.primary( + fullWidth: true, + onPressed: state.isValid + ? () => context + .read() + .add(EmergencyContactsSaved()) + : null, + child: state.status == EmergencyContactStatus.saving + ? SizedBox( + height: 20.0, + width: 20.0, + child: CircularProgressIndicator( + strokeWidth: 2, + valueColor: + AlwaysStoppedAnimation(UiColors.primaryForeground), ), - ), + ) + : Text( + 'Save & Continue', + ), ), ), ); diff --git a/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/staff_emergency_contact_module.dart b/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/staff_emergency_contact_module.dart index 3245fd70..5dfb7a30 100644 --- a/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/staff_emergency_contact_module.dart +++ b/apps/mobile/packages/features/staff/profile_sections/onboarding/emergency_contact/lib/src/staff_emergency_contact_module.dart @@ -28,7 +28,7 @@ class StaffEmergencyContactModule extends Module { ); // BLoC - i.addLazySingleton( + i.add( () => EmergencyContactBloc( getEmergencyContacts: i.get(), saveEmergencyContacts: i.get(),