feat(diary): consultant comments

This commit is contained in:
Username1548
2025-04-24 04:20:24 +07:00
parent 267cc38a0b
commit 3754d047fb
102 changed files with 6021 additions and 494 deletions

View File

@@ -14,7 +14,7 @@ import 'package:eatvio_app/features/chat/presentation/bloc/chat_room_cubit/chat_
import 'package:eatvio_app/features/chat/repositories/chat_repository.dart';
import 'package:eatvio_app/features/my_finance/models/card_model.dart';
import 'package:eatvio_app/features/my_finance/repositories/cards_repository.dart';
import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart';
import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class ChatRoomCubit extends Cubit<ChatRoomState> {
@@ -57,13 +57,13 @@ class ChatRoomCubit extends Cubit<ChatRoomState> {
Future<void> checkCards() async {
try {
final cards = await cardsRepository.getCards();
setCard(cards: cards);
} catch (e) {
emit(const ChatRoomState.error(errorMessage: 'Ошибка получеия данных'));
_setCard(cards: cards);
} catch (e, st) {
log(e.toString(), stackTrace: st);
}
}
void setCard({required List<CardModel> cards}) {
void _setCard({required List<CardModel> cards}) {
final currentState = state;
if (currentState is ChatRoomStateLoaded) {
if (cards.where((card) => card.isDefault).isNotEmpty) {
@@ -75,15 +75,27 @@ class ChatRoomCubit extends Cubit<ChatRoomState> {
initChat(String chatId) async {
try {
final chatRoom = await chatRepository.getChatRoom(chatId);
ChosenPlanModel? chosenPlan;
if (chatRoom.chosenPlanId != null) {
chosenPlan = await chatRepository.getChosenPlan(id: chatRoom.chosenPlanId!);
}
final chatMessages = await chatRepository.getChatMessages(chatId, currentPage);
lastPage = chatMessages.meta.lastPage;
await _subscribeToChatChannel(chatId: chatId);
emit(
ChatRoomState.loaded(
chatRoom: chatRoom.copyWith(chosenPlan: chosenPlan),
chatMessages: chatMessages.messagesList,
isTyping: false,
isLoading: isLoading,
hasCard: false,
),
);
emit(ChatRoomState.loaded(chatRoom: chatRoom, chatMessages: chatMessages.messagesList, isTyping: false, isLoading: isLoading, hasCard: false));
// final cards = await cardsRepository.getCards();
// setCard(cards: cards);
if (chatRoom.chosenPlan?.consultantId == chatRoom.users.receiver.id) {
await checkCards();
}
} catch (e) {
log(e.toString());
typingSubscription?.cancel();
@@ -93,14 +105,26 @@ class ChatRoomCubit extends Cubit<ChatRoomState> {
}
}
Future<void> updateChosenPlanState() async {
final currentState = state;
if (currentState is ChatRoomStateLoaded) {
final chosenPlanId = currentState.chatRoom.chosenPlanId;
if (chosenPlanId != null) {
final chosenPlan = await chatRepository.getChosenPlan(id: chosenPlanId);
emit(currentState.copyWith.chatRoom(chosenPlan: chosenPlan));
}
}
}
Future<bool> choseStartPlanDate(DateTime date) async {
try {
if (state is! ChatRoomStateLoaded) return false;
final planId = (state as ChatRoomStateLoaded).chatRoom.chosenPlan?.id;
final planId = (state as ChatRoomStateLoaded).chatRoom.chosenPlanId;
if (planId == null) return false;
final stringDate = date.format('yyyy-MM-dd');
await chatRepository.choseStartPlanDate(id: planId, date: {'start_date': stringDate});
emit((state as ChatRoomStateLoaded).copyWith.chatRoom.chosenPlan?.call(chosenPlanState: ChosenPlanStateEnum.stateStartDateHasBeenSet) ?? state);
final chosenPlan = await chatRepository.getChosenPlan(id: planId);
emit((state as ChatRoomStateLoaded).copyWith.chatRoom(chosenPlan: chosenPlan));
return true;
} catch (e, st) {
log(e.toString(), stackTrace: st);
@@ -111,8 +135,7 @@ class ChatRoomCubit extends Cubit<ChatRoomState> {
Future<void> cancelChosenPlan({required String chatId, required int planId}) async {
try {
await chatRepository.cancelChosenPlan(id: planId);
final chatRoom = await chatRepository.getChatRoom(chatId);
emit((state as ChatRoomStateLoaded).copyWith(chatRoom: chatRoom));
emit((state as ChatRoomStateLoaded).copyWith.chatRoom(chosenPlan: null));
} catch (e) {
emit(const ChatRoomState.error(errorMessage: 'Ошибка получеия данных'));
}
@@ -133,7 +156,8 @@ class ChatRoomCubit extends Cubit<ChatRoomState> {
typingSubscription = wsManager.clientTypingStream?.listen((event) {
emit((state as ChatRoomStateLoaded).copyWith(isTyping: true, isLoading: isLoading));
EasyDebounce.debounce('client-typing', const Duration(seconds: 3), () => emit((state as ChatRoomStateLoaded).copyWith(isTyping: false, isLoading: isLoading)));
EasyDebounce.debounce(
'client-typing', const Duration(seconds: 3), () => emit((state as ChatRoomStateLoaded).copyWith(isTyping: false, isLoading: isLoading)));
});
}

View File

@@ -14,7 +14,6 @@ import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/core/theme/custom_text_style.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/chat/presentation/widgets/notification_banner.dart';
import 'package:eatvio_app/features/chat/presentation/widgets/order_card.dart';
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
import 'package:eatvio_app/features/order_info/presentation/info_by_order_screen.dart';
import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart';
@@ -85,15 +84,24 @@ class _ChatScreenState extends State<ChatScreen> {
_buildChat(BuildContext context, ChatRoomStateLoaded state) {
final chosenPlan = state.chatRoom.chosenPlan;
final amIConsultant = chosenPlan?.consultantId == state.chatRoom.users.sender.id;
final showAboutOrderButton = showableChatBadgeStates.contains(chosenPlan?.chosenPlanState);
final showUserDetailsButton = amIConsultant &&
[
ChosenPlanStateEnum.stateStartDateHasBeenSet,
ChosenPlanStateEnum.statePendingPayment,
ChosenPlanStateEnum.stateInCoordination,
].contains(chosenPlan?.chosenPlanState);
final showAboutOrderButton =
state.chatRoom.chosenPlan != null && state.chatRoom.chosenPlan!.chosenPlanState != ChosenPlanStateEnum.stateCanceledByTheInitiator;
BannerType? bannerType;
if (amIConsultant && state.hasCard) {
if (chosenPlan == null) {
bannerType = null;
} else if (amIConsultant && state.hasCard) {
bannerType = BannerType.card;
} else if (amIConsultant && chosenPlan?.chosenPlanState == ChosenPlanStateEnum.stateInCoordination) {
} else if (amIConsultant && chosenPlan.chosenPlanState == ChosenPlanStateEnum.stateInCoordination) {
bannerType = BannerType.date;
} else if (!amIConsultant &&
(chosenPlan?.chosenPlanState == ChosenPlanStateEnum.stateStartDateHasBeenSet ||
chosenPlan?.chosenPlanState == ChosenPlanStateEnum.statePendingPayment)) {
(chosenPlan.chosenPlanState == ChosenPlanStateEnum.stateStartDateHasBeenSet || chosenPlan.chosenPlanState == ChosenPlanStateEnum.statePendingPayment)) {
bannerType = BannerType.payment;
}
return Scaffold(
@@ -254,15 +262,15 @@ class _ChatScreenState extends State<ChatScreen> {
itemCount: state.chatMessages.length + (state.isLoading ? 1 : 0),
),
const SizedBox(height: 16),
if (chosenPlan != null) ...[
OrderCard(
plan: chosenPlan.plan,
isCustomerView: !amIConsultant,
optionType: chosenPlan.optionType,
onCancel: () async {
await context.read<ChatRoomCubit>().cancelChosenPlan(chatId: state.chatRoom.id, planId: chosenPlan.id);
},
),
if (showUserDetailsButton) ...[
// OrderCard(
// plan: chosenPlan.plan,
// isCustomerView: !amIConsultant,
// optionType: chosenPlan.optionType,
// onCancel: () async {
// await context.read<ChatRoomCubit>().cancelChosenPlan(chatId: state.chatRoom.id, planId: chosenPlan.id);
// },
// ),
if (amIConsultant)
Padding(
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
@@ -394,7 +402,7 @@ class _ChatScreenState extends State<ChatScreen> {
right: 15,
left: 16,
child: AboutOrderButton(
onTap: () {
onTap: () async {
GoRouter.of(context).push(InfoByOrderScreen.path, extra: {'planId': state.chatRoom.chosenPlan?.id});
},
)),

View File

@@ -5,6 +5,7 @@ import 'package:eatvio_app/features/chat/presentation/bloc/chat_room_cubit/chat_
import 'package:eatvio_app/features/chat/presentation/bloc/chat_room_cubit/chat_room_state.dart';
import 'package:eatvio_app/features/chat/presentation/pages/payment_screen.dart';
import 'package:eatvio_app/features/chat/presentation/widgets/chose_plan_date_widget.dart';
import 'package:eatvio_app/features/my_finance/presentation/pages/card_settings.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -76,7 +77,11 @@ class _NotificationBannerState extends State<NotificationBanner> {
),
const SizedBox(height: 12),
GestureDetector(
onTap: () {},
onTap: () {
GoRouter.of(context).pushReplacement(
CardSettingsScreen.path,
);
},
child: Text(s.add_card, style: TextStyles.textLSemibold.copyWith(color: appTheme.blueA400)),
),
const SizedBox(height: 16),