Skip to content

Commit

Permalink
Add 'optional' option to portal fields
Browse files Browse the repository at this point in the history
  • Loading branch information
hillelcoren committed Mar 6, 2023
1 parent 9c8f26c commit 2e049d9
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 18 deletions.
21 changes: 21 additions & 0 deletions lib/data/models/company_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1250,11 +1250,16 @@ abstract class RegistrationFieldEntity
return _$RegistrationFieldEntity._(
key: '',
required: false,
visible: false,
);
}

RegistrationFieldEntity._();

static const SETTING_HIDDEN = 'hidden';
static const SETTING_OPTIONAL = 'optional';
static const SETTING_REQUIRED = 'required';

@override
@memoized
int get hashCode;
Expand All @@ -1263,6 +1268,22 @@ abstract class RegistrationFieldEntity

bool get required;

bool get visible;

String get setting {
if (required) {
return SETTING_REQUIRED;
} else if (visible) {
return SETTING_OPTIONAL;
} else {
return SETTING_HIDDEN;
}
}

// ignore: unused_element
static void _initializeBuilder(RegistrationFieldEntityBuilder builder) =>
builder..visible = false;

static Serializer<RegistrationFieldEntity> get serializer =>
_$registrationFieldEntitySerializer;
}
Expand Down
34 changes: 29 additions & 5 deletions lib/data/models/company_model.g.dart

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

71 changes: 58 additions & 13 deletions lib/ui/settings/client_portal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter/services.dart';
// Package imports:
import 'package:flutter_redux/flutter_redux.dart';
import 'package:flutter_styled_toast/flutter_styled_toast.dart';
import 'package:invoiceninja_flutter/data/models/company_model.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:url_launcher/url_launcher.dart';

Expand Down Expand Up @@ -511,19 +512,63 @@ class _ClientPortalState extends State<ClientPortal>
),
FormCard(
isLast: true,
children: company.clientRegistrationFields
.map((field) => SwitchListTile(
activeColor: Theme.of(context).colorScheme.secondary,
title: Text(localization.lookup(field.key)),
value: field.required,
onChanged: (value) {
final index =
company.clientRegistrationFields.indexOf(field);
viewModel.onCompanyChanged(company.rebuild((b) => b
..clientRegistrationFields[index] = field.rebuild(
(b) => b..required = !field.required)));
}))
.toList(),
children: company.clientRegistrationFields.map((field) {
return Row(
children: [
Expanded(
child: Text(localization.lookup(field.key)),
),
Expanded(
child: AppDropdownButton<String>(
value: field.setting,
onChanged: (dynamic value) {
final index = company.clientRegistrationFields
.indexOf(field);
viewModel.onCompanyChanged(company.rebuild((b) =>
b
..clientRegistrationFields[index] =
field.rebuild((b) => b
..required = value ==
RegistrationFieldEntity
.SETTING_REQUIRED
..visible = value ==
RegistrationFieldEntity
.SETTING_REQUIRED ||
value ==
RegistrationFieldEntity
.SETTING_OPTIONAL)));
},
items: [
DropdownMenuItem(
value: RegistrationFieldEntity.SETTING_HIDDEN,
child: Text(localization.hidden),
),
DropdownMenuItem(
value: RegistrationFieldEntity.SETTING_OPTIONAL,
child: Text(localization.optional),
),
DropdownMenuItem(
value: RegistrationFieldEntity.SETTING_REQUIRED,
child: Text(localization.requiredWord),
),
],
),
),
],
);

return SwitchListTile(
activeColor: Theme.of(context).colorScheme.secondary,
title: Text(localization.lookup(field.key)),
value: field.required,
onChanged: (value) {
final index =
company.clientRegistrationFields.indexOf(field);
viewModel.onCompanyChanged(company.rebuild((b) => b
..clientRegistrationFields[index] = field.rebuild(
(b) => b..required = !field.required)));
});
}).toList(),
),
],
),
Expand Down
10 changes: 10 additions & 0 deletions lib/utils/i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ mixin LocalizationsProvider on LocaleCodeAware {
static final Map<String, Map<String, String>> _localizedValues = {
'en': {
// STARTER: lang key - do not remove comment
'required': 'Required',
'hidden': 'Hidden',
'payment_links': 'Payment Links',
'action': 'Action',
'upgrade_to_paid_plan_to_schedule':
Expand Down Expand Up @@ -96825,6 +96827,14 @@ mixin LocalizationsProvider on LocaleCodeAware {
_localizedValues[localeCode]['action'] ??
_localizedValues['en']['action'];

String get hidden =>
_localizedValues[localeCode]['hidden'] ??
_localizedValues['en']['hidden'];

String get requiredWord =>
_localizedValues[localeCode]['required'] ??
_localizedValues['en']['required'];

// STARTER: lang field - do not remove comment

String lookup(String key) {
Expand Down

0 comments on commit 2e049d9

Please sign in to comment.