Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hcmpre-1259, hcmpre-1260: facility campiagn homepage and institute selection screen #612

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions apps/health_campaign_field_worker_app/lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import 'package:referral_reconciliation/router/referral_reconciliation_router.gm
import 'package:registration_delivery/registration_delivery.dart';
import 'package:registration_delivery/router/registration_delivery_router.gm.dart';
import 'package:survey_form/router/survey_form_router.gm.dart';
import 'package:institution_campaign/router/institution_campaign_router.gm.dart';

import '../blocs/app_initialization/app_initialization.dart';
import '../blocs/auth/auth.dart';
Expand Down Expand Up @@ -360,6 +361,17 @@ class _HomePageState extends LocalizedState<HomePage> {
},
),
),

i18.home.institutionLabel: homeShowcaseData.instituteCampaign.buildWith(
child: HomeItemCard(
icon: Icons.account_balance,
label: i18.home.institutionLabel,
onPressed: () async {
await context.router.push(const InstitutionCampaignWrapperRoute());
},
),
),

i18.home.closedHouseHoldLabel: homeShowcaseData.closedHouseHold.buildWith(
child: HomeItemCard(
icon: Icons.home,
Expand Down Expand Up @@ -511,7 +523,8 @@ class _HomePageState extends LocalizedState<HomePage> {
homeShowcaseData.warehouseManagerManageStock.showcaseKey,
i18.home.stockReconciliationLabel:
homeShowcaseData.wareHouseManagerStockReconciliation.showcaseKey,
i18.home.mySurveyForm: homeShowcaseData.supervisorMySurveyForm.showcaseKey,
i18.home.mySurveyForm:
homeShowcaseData.supervisorMySurveyForm.showcaseKey,
i18.home.fileComplaint:
homeShowcaseData.distributorFileComplaint.showcaseKey,
i18.home.syncDataLabel: homeShowcaseData.distributorSyncData.showcaseKey,
Expand All @@ -524,11 +537,13 @@ class _HomePageState extends LocalizedState<HomePage> {
i18.home.closedHouseHoldLabel:
homeShowcaseData.closedHouseHold.showcaseKey,
i18.home.dashboard: homeShowcaseData.dashBoard.showcaseKey,
i18.home.institutionLabel: homeShowcaseData.instituteCampaign.showcaseKey,
};

final homeItemsLabel = <String>[
// INFO: Need to add items label of package Here
i18.home.beneficiaryLabel,
i18.home.institutionLabel,
i18.home.closedHouseHoldLabel,
i18.home.manageStockLabel,
i18.home.stockReconciliationLabel,
Expand All @@ -548,7 +563,8 @@ class _HomePageState extends LocalizedState<HomePage> {
.map((e) => e.displayName)
.toList()
.contains(element) ||
element == i18.home.db)
element == i18.home.db ||
element == i18.home.institutionLabel)
.toList();

final showcaseKeys = filteredLabels
Expand Down Expand Up @@ -725,14 +741,18 @@ void setPackagesSingleton(BuildContext context) {
loggedInIndividualId: context.loggedInIndividualId ?? '',
loggedInUserUuid: context.loggedInUserUuid,
appVersion: Constants().version,
isHealthFacilityWorker: context.loggedInUserRoles.where((role) => role.code == RolesType.healthFacilityWorker.toValue()).toList().isNotEmpty,
isHealthFacilityWorker: context.loggedInUserRoles
.where((role) =>
role.code == RolesType.healthFacilityWorker.toValue())
.toList()
.isNotEmpty,
roles: context.read<AuthBloc>().state.maybeMap(
orElse: () => const Offstage(),
authenticated: (res) {
return res.userModel.roles
.map((e) => e.code.snakeCase.toUpperCase())
.toList();
}),
orElse: () => const Offstage(),
authenticated: (res) {
return res.userModel.roles
.map((e) => e.code.snakeCase.toUpperCase())
.toList();
}),
);

ReferralReconSingleton().setInitialData(
Expand Down
28 changes: 23 additions & 5 deletions apps/health_campaign_field_worker_app/lib/router/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import 'package:referral_reconciliation/router/referral_reconciliation_router.da
import 'package:referral_reconciliation/router/referral_reconciliation_router.gm.dart';
import 'package:registration_delivery/router/registration_delivery_router.dart';
import 'package:registration_delivery/router/registration_delivery_router.gm.dart';
import 'package:institution_campaign/router/institution_campaign_router.dart';
import 'package:institution_campaign/router/institution_campaign_router.gm.dart';

import '../blocs/localization/app_localization.dart';
import '../pages/acknowledgement.dart';
Expand Down Expand Up @@ -48,7 +50,8 @@ part 'app_router.gr.dart';
ClosedHouseholdPackageRoute,
DashboardRoute,
SurveyFormRoute,
ComplaintsRoute
ComplaintsRoute,
InstitutionCampaignRouter
],
)
class AppRouter extends _$AppRouter {
Expand Down Expand Up @@ -229,10 +232,13 @@ class AppRouter extends _$AppRouter {
path: '',
),
AutoRoute(
page: SurveyFormBoundaryViewRoute.page, path: 'view-boundary'),
page: SurveyFormBoundaryViewRoute.page,
path: 'view-boundary'),
AutoRoute(page: SurveyFormViewRoute.page, path: 'view'),
AutoRoute(page: SurveyFormPreviewRoute.page, path: 'preview'),
AutoRoute(page: SurveyFormAcknowledgementRoute.page, path: 'surveyForm-acknowledgement'),
AutoRoute(
page: SurveyFormAcknowledgementRoute.page,
path: 'surveyForm-acknowledgement'),
]),
AutoRoute(
page: BeneficiaryAcknowledgementRoute.page,
Expand Down Expand Up @@ -320,8 +326,8 @@ class AppRouter extends _$AppRouter {

// Attendance Route
AutoRoute(
page: MarkAttendanceRoute.page,
path: 'mark-attendance',
page: MarkAttendanceRoute.page,
path: 'mark-attendance',
),
AutoRoute(
page: ManageAttendanceRoute.page,
Expand Down Expand Up @@ -399,6 +405,18 @@ class AppRouter extends _$AppRouter {
page: SearchReferralReconciliationsRoute.page,
path: 'search-referrals',
),

/// Institution Campaign Route
AutoRoute(
page: InstitutionCampaignWrapperRoute.page,
path: 'institution-campaign',
children: [
AutoRoute(
page: InstitutionTypeRoute.page,
path: 'institution-type',
initial: true,
)
])
],
)
];
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ extension ContextUtilityExtensions on BuildContext {
AttendanceSingleton().setBoundary(boundary: selectedBoundary);
LocationTrackerSingleton()
.setBoundaryName(boundaryName: selectedBoundary.code!);
InstitutionCampaignSingleton().setBoundary(boundary: selectedBoundary);
return selectedBoundary;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:referral_reconciliation/utils/utils.dart';
import 'package:registration_delivery/registration_delivery.dart';
// Importing necessary packages and files
import 'package:survey_form/utils/utils.dart';
import 'package:institution_campaign/utils/utils.dart';

import '../../blocs/auth/auth.dart';
import '../../blocs/project/project.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ class HomeShowcase {
String get deleteAll {
return 'WAREHOUSE_MANAGER_HOME_SHOWCASE_DELETE_ALL';
}

String get instituteCampaign {
return "INSTITUTE_CAMPAIGN_SHOWCASE";
}
}

class SelectStockShowcase {
Expand Down Expand Up @@ -510,7 +514,6 @@ class ComplaintsInboxShowcase {
}
}


class ForgotPassword {
const ForgotPassword();

Expand Down Expand Up @@ -561,6 +564,8 @@ class Home {
String get manageAttendanceLabel => 'HOME_MANAGE_ATTENDANCE_LABEL';

String get closedHouseHoldLabel => 'HOME_CLOSE_HOUSEHOLD_LABEL';

String get institutionLabel => "HOME_INSTITUTION_CAMPAIGN_LABEL";
}

class AcknowledgementSuccess {
Expand Down Expand Up @@ -1014,7 +1019,6 @@ class PrivacyPolicy {
String get privacyNoticeText => 'PRIVACY_POLICY_TEXT';
String get privacyPolicyLinkText => 'PRIVACY_POLICY_LINK_TEXT';
String get privacyPolicyValidationText => 'PRIVACY_POLICY_VALIDATION_TEXT';

}

class Dashboard {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ import 'package:referral_reconciliation/blocs/app_localization.dart'
as referral_reconciliation_localization;
import 'package:registration_delivery/blocs/app_localization.dart'
as registration_delivery_localization;
import 'package:digit_components/blocs/localization.dart' as component_localization;
import 'package:digit_components/blocs/localization.dart'
as component_localization;
import 'package:survey_form/blocs/app_localization.dart'
as survey_form_localization;
import 'package:institution_campaign/blocs/app_localization.dart'
as institution_campaign_localization;

import '../blocs/localization/app_localization.dart';
import '../data/local_store/no_sql/schema/app_configuration.dart';
Expand Down Expand Up @@ -82,5 +85,10 @@ getAppLocalizationDelegates({
LocalizationLocalRepository().returnLocalizationFromSQL(sql) as Future,
appConfig.languages!,
),
institution_campaign_localization.InstitutionCampaignLocalization
.getDelegate(
LocalizationLocalRepository().returnLocalizationFromSQL(sql) as Future,
appConfig.languages!,
)
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,7 @@ class _HomePageShowcaseData {
final closedHouseHold = ShowcaseItemBuilder(
messageLocalizationKey: i18.home.closedHouseHoldLabel,
);

final instituteCampaign = ShowcaseItemBuilder(
messageLocalizationKey: i18.homeShowcase.instituteCampaign);
}
9 changes: 8 additions & 1 deletion apps/health_campaign_field_worker_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ packages:
path: "../../packages/closed_household"
relative: true
source: path
version: "1.0.1+1"
version: "1.0.2-dev.1"
code_builder:
dependency: transitive
description:
Expand Down Expand Up @@ -1334,6 +1334,13 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.2.1+1"
institution_campaign:
dependency: "direct overridden"
description:
path: "../../packages/institution_campaign"
relative: true
source: path
version: "0.0.1"
integration_test:
dependency: "direct dev"
description: flutter
Expand Down
52 changes: 52 additions & 0 deletions packages/institution_campaign/lib/blocs/app_localization.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:flutter/material.dart';

import 'institution_campaign_localization_delegate.dart';

// Class responsible for handling institution campaign localization
class InstitutionCampaignLocalization {
final Locale locale;
final Future<dynamic> localizedStrings;
final List<dynamic> languages;

InstitutionCampaignLocalization(
this.locale, this.localizedStrings, this.languages);

// Method to get the current localization instance from context
static InstitutionCampaignLocalization of(BuildContext context) {
return Localizations.of<InstitutionCampaignLocalization>(
context, InstitutionCampaignLocalization)!;
}

static final List<dynamic> _localizedStrings = <dynamic>[];

// Method to get the delegate for localization
static LocalizationsDelegate<InstitutionCampaignLocalization> getDelegate(
Future<dynamic> localizedStrings, List<dynamic> languages) =>
InstitutionCampaignLocalizationDelegate(localizedStrings, languages);

// Method to load localized strings
Future<bool> load() async {
_localizedStrings.clear();
// Iterate over localized strings and filter based on locale
for (var element in await localizedStrings) {
if (element.locale == '${locale.languageCode}_${locale.countryCode}') {
_localizedStrings.add(element);
}
}

return true;
}

// Method to translate a given localized value
String translate(String localizedValues) {
if (_localizedStrings.isEmpty) {
return localizedValues;
} else {
final index = _localizedStrings.indexWhere(
(medium) => medium.code == localizedValues,
);

return index != -1 ? _localizedStrings[index].message : localizedValues;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';

import 'app_localization.dart';

class InstitutionCampaignLocalizationDelegate
extends LocalizationsDelegate<InstitutionCampaignLocalization> {
final Future<dynamic> localizedStrings;
final List<dynamic> languages;

const InstitutionCampaignLocalizationDelegate(
this.localizedStrings, this.languages);

@override
bool isSupported(Locale locale) {
return languages.map((e) {
final results = e.value.split('_');
if (results.isNotEmpty) return results.first;
}).contains(locale.languageCode);
}

@override
Future<InstitutionCampaignLocalization> load(Locale locale) async {
InstitutionCampaignLocalization localization =
InstitutionCampaignLocalization(locale, localizedStrings, languages);
await localization.load();

return localization;
}

@override
bool shouldReload(
covariant LocalizationsDelegate<InstitutionCampaignLocalization> old) {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

@RoutePage()
class InstitutionCampaignWrapperPage extends StatelessWidget {
const InstitutionCampaignWrapperPage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
body: const AutoRouter(),
);
}
}
Loading