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

added data about the approval edit and isRegistered for the client an… #71

Merged
merged 1 commit into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<application android:label="appointments" android:name="${applicationName}" android:icon="@mipmap/ic_launcher"
<application android:label="AleenNails\nAdmin" android:name="${applicationName}" android:icon="@mipmap/ic_launcher"
android:requestLegacyExternalStorage="true" android:enableOnBackInvokedCallback="true">

<activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize" >
Expand Down
25 changes: 20 additions & 5 deletions lib/data_types/components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,15 @@ class Client {
String? generalNotes; // General notes about client
DateTime? birthday; // Birthday date
DateTime creationDate; // Client creation date
DateTime? acceptedDate; // Birthday date
int discount; // general discount for client
bool isTrusted; // Trusted user
String imageURL; // Image URL for quick download
List<ClientAppointment> appointments;
bool isApprovedByAdmin; // Admin approved this account
bool? isApprovedByAdmin; // Admin approved this account
String?
lasApprovalEditorId; // last admin id that edited the isApprovedByAdmin
DateTime? lasApprovalEditDate; // last edit date for isApprovedByAdmin
bool isRegistered; // is it a registered user (not created by admin)

double get totalRevenue {
return appointments.fold<double>(0, (sum, item) => sum + item.totalCost);
Expand Down Expand Up @@ -428,12 +431,14 @@ class Client {
this.generalNotes,
this.birthday,
required this.creationDate,
this.acceptedDate,
this.discount = 0,
this.isTrusted = false,
this.imageURL = '',
this.appointments = const [],
this.isApprovedByAdmin = false,
this.lasApprovalEditorId,
this.lasApprovalEditDate,
this.isRegistered = false,
});

Map<String, dynamic> toJson() {
Expand All @@ -445,11 +450,15 @@ class Client {
'generalNotes': generalNotes,
'birthday': birthday != null ? Timestamp.fromDate(birthday!) : '',
'creationDate': Timestamp.fromDate(creationDate),
'acceptedDate': Timestamp.fromDate(creationDate),
'discount': discount,
'isTrusted': isTrusted,
'imageURL': imageURL,
'isApprovedByAdmin': isApprovedByAdmin,
'lasApprovalEditorId': lasApprovalEditorId,
'lasApprovalEditDate': lasApprovalEditDate != null
? Timestamp.fromDate(lasApprovalEditDate!)
: null,
'isRegistered': isRegistered,
};
}

Expand Down Expand Up @@ -479,7 +488,13 @@ class Client {
appointments: doc['appointments'] == null
? []
: loadAppointmentsFromDoc(doc['appointments']),
isApprovedByAdmin: doc['isApprovedByAdmin'] ?? false,
isApprovedByAdmin: doc['isApprovedByAdmin'],
lasApprovalEditorId: doc['lasApprovalEditorId'],
lasApprovalEditDate: doc['lasApprovalEditDate'] != null &&
doc['lasApprovalEditDate'].toString().isNotEmpty
? doc['lasApprovalEditDate'].toDate()
: null,
isRegistered: doc['isRegistered'] ?? false,
);
}
}
Expand Down
23 changes: 17 additions & 6 deletions lib/providers/clients_mgr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class ClientsMgr extends ChangeNotifier {
}
}

Future<void> updateClient(Client updatedClient) async {
Future<void> updateClient(String? adminId, Client updatedClient) async {
/// Validate that phone number is not used by another client
bool phoneAvailable = await checkPhoneNumberAvailability(
updatedClient.phone, updatedClient.id);
Expand All @@ -231,16 +231,27 @@ class ClientsMgr extends ChangeNotifier {

/// Update existing Client - update DB
CollectionReference clientsColl = _fs.collection(clientsCollection);
if (initialized) {
var oldClientRes = _clients.where((c) => c.id == updatedClient.id);
if (oldClientRes.isNotEmpty &&
oldClientRes.first.isApprovedByAdmin !=
updatedClient.isApprovedByAdmin) {
updatedClient.lasApprovalEditorId = adminId;
updatedClient.lasApprovalEditDate = DateTime.now();
}
}
var data = updatedClient.toJson();
clientsColl.doc(updatedClient.id).update(data);
updateClientAppointments(updatedClient);
}

Future<void> updateClientApproval(String clientId, bool approve) async {
await _fs
.collection(clientsCollection)
.doc(clientId)
.update({'isApprovedByAdmin': approve});
Future<void> updateClientApproval(
String? adminId, String clientId, bool approve) async {
await _fs.collection(clientsCollection).doc(clientId).update({
'isApprovedByAdmin': approve,
'lasApprovalEditorId': adminId,
'lasApprovalEditDate': Timestamp.fromDate(DateTime.now()),
});
}

/// Client selection
Expand Down
16 changes: 11 additions & 5 deletions lib/screens/home/clients/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import 'package:flutter/services.dart';
import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:provider/provider.dart';

import '../../../providers/auth_mgr.dart';

class ClientWidget extends StatefulWidget {
final Client? client;
const ClientWidget({Key? key, this.client}) : super(key: key);
Expand All @@ -42,7 +44,7 @@ class _ClientWidgetState extends State<ClientWidget> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
int clientDiscount = 0;
bool trustedClient = true;
bool blockedClient = false;
bool blockedClient = true;
bool autoValidate = false;
String imageURL = '';
bool isSaveDisabled = true;
Expand All @@ -63,7 +65,7 @@ class _ClientWidgetState extends State<ClientWidget> {
_noteController.text = widget.client!.generalNotes!;
clientDiscount = widget.client!.discount;
trustedClient = widget.client!.isTrusted;
blockedClient = !widget.client!.isApprovedByAdmin;
blockedClient = !(widget.client!.isApprovedByAdmin == true);
birthdayDate = widget.client!.birthday;
imageURL = widget.client!.imageURL;
}
Expand Down Expand Up @@ -639,6 +641,7 @@ class _ClientWidgetState extends State<ClientWidget> {
if (form!.validate()) {
showLoaderDialog(context);
final clientMgr = Provider.of<ClientsMgr>(context, listen: false);
final authMgr = Provider.of<AuthenticationMgr>(context, listen: false);
String clientID = widget.client == null ? '' : widget.client!.id;

Client client = Client(
Expand All @@ -647,14 +650,16 @@ class _ClientWidgetState extends State<ClientWidget> {
phone: _phoneController.text,
address: _addressController.text,
email: _emailController.text,
creationDate: DateTime.now(),
creationDate: widget.client?.creationDate ?? DateTime.now(),
birthday: birthdayDate,
generalNotes: _noteController.text,
discount: clientDiscount,
isTrusted: trustedClient,
isApprovedByAdmin: !blockedClient,
acceptedDate: DateTime.now(),
imageURL: imageURL,
lasApprovalEditorId: widget.client?.lasApprovalEditorId,
lasApprovalEditDate: widget.client?.lasApprovalEditDate,
isRegistered: widget.client?.isRegistered ?? false,
);

if (widget.client == null) {
Expand All @@ -671,7 +676,8 @@ class _ClientWidgetState extends State<ClientWidget> {
}
} else {
try {
await clientMgr.updateClient(client);
await clientMgr.updateClient(
authMgr.getLoggedInAdminEmail(), client);
await clientMgr.setSelectedClient(clientID: client.id);
close();
showUpdateClientSuccessMessage();
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/home/clients/client_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class _ClientDetailsState extends State<ClientDetails> {
),
),
Text(
!client.isApprovedByAdmin
!(client.isApprovedByAdmin == true)
? Languages.of(context)!.yesLabel.toTitleCase()
: Languages.of(context)!.noLabel.toTitleCase(),
maxLines: 1,
Expand Down
6 changes: 4 additions & 2 deletions lib/screens/home/notification/approval_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class _ApprovalRequestState extends State<ApprovalRequest> {
final notificationsMgr =
Provider.of<NotificationsMgr>(context, listen: false);
final authMgr = Provider.of<AuthenticationMgr>(context, listen: false);
await clientsMgr.updateClientApproval(client.id, true);
await clientsMgr.updateClientApproval(
authMgr.getLoggedInAdminEmail(), client.id, true);
clientUpdatedSuccessfullyMessage();
// delete notification
await notificationsMgr.deleteNotification(
Expand All @@ -62,7 +63,8 @@ class _ApprovalRequestState extends State<ApprovalRequest> {
final notificationsMgr =
Provider.of<NotificationsMgr>(context, listen: false);
final authMgr = Provider.of<AuthenticationMgr>(context, listen: false);
await clientsMgr.updateClientApproval(client.id, false);
await clientsMgr.updateClientApproval(
authMgr.getLoggedInAdminEmail(), client.id, false);
clientUpdatedSuccessfullyMessage();
// delete notification
await notificationsMgr.deleteNotification(
Expand Down
3 changes: 2 additions & 1 deletion lib/widget/client/client_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class ClientCard extends StatelessWidget {
trailing: Row(
children: [
Visibility(
visible: !clientCardProps.contactDetails.isApprovedByAdmin,
visible:
!(clientCardProps.contactDetails.isApprovedByAdmin == true),
child: Padding(
padding: EdgeInsets.only(
left: rSize(10),
Expand Down
4 changes: 2 additions & 2 deletions lib/widget/notification_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class NotificationCard extends StatelessWidget {
final authMgr = Provider.of<AuthenticationMgr>(context, listen: false);
final clientsMgr = Provider.of<ClientsMgr>(context, listen: false);
// approve client
await clientsMgr.updateClientApproval(
await clientsMgr.updateClientApproval(authMgr.getLoggedInAdminEmail(),
notificationCardProps.notificationDetails.data['client_id'], true);
clientUpdatedSuccessfullyMessage();
// delete notification
Expand All @@ -64,7 +64,7 @@ class NotificationCard extends StatelessWidget {
final authMgr = Provider.of<AuthenticationMgr>(context, listen: false);
final clientsMgr = Provider.of<ClientsMgr>(context, listen: false);
// deny client
await clientsMgr.updateClientApproval(
await clientsMgr.updateClientApproval(authMgr.getLoggedInAdminEmail(),
notificationCardProps.notificationDetails.data['client_id'], false);
clientUpdatedSuccessfullyMessage();
// delete notification
Expand Down