Skip to content

Commit

Permalink
Merge branch 'development' of github.com:UNICEFECAR/USupport-mobile i…
Browse files Browse the repository at this point in the history
…nto fix/issue_76
  • Loading branch information
georgiganchev-7DIGIT committed Dec 22, 2023
2 parents 49ae8da + c105d4e commit 02fdd7c
Show file tree
Hide file tree
Showing 26 changed files with 153 additions and 9 deletions.
4 changes: 4 additions & 0 deletions i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import {
RequireDataAgreemant,
RequireRegistration,
HowItWorksMyQA,
DeleteChatHistory,
} from "./src/modals/locales.js";

import { TabNavigation } from "./src/navigation/locales.js";
Expand Down Expand Up @@ -180,6 +181,7 @@ const resources = {
"require-data-agreement": RequireDataAgreemant.en,
"require-registration": RequireRegistration.en,
"how-it-works-my-qa": HowItWorksMyQA.en,
"delete-chat-history": DeleteChatHistory.en,

// Navigation
"tab-navigation": TabNavigation.en,
Expand Down Expand Up @@ -271,6 +273,7 @@ const resources = {
"require-data-agreement": RequireDataAgreemant.ru,
"require-registration": RequireRegistration.ru,
"how-it-works-my-qa": HowItWorksMyQA.ru,
"delete-chat-history": DeleteChatHistory.ru,

// Navigation
"tab-navigation": TabNavigation.ru,
Expand Down Expand Up @@ -362,6 +365,7 @@ const resources = {
"require-data-agreement": RequireDataAgreemant.kk,
"require-registration": RequireRegistration.kk,
"how-it-works-my-qa": HowItWorksMyQA.kk,
"delete-chat-history": DeleteChatHistory.kk,

// Navigation
"tab-navigation": TabNavigation.kk,
Expand Down
1 change: 1 addition & 0 deletions src/blocks/ActivityHistory/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"client_camera_on": "The client has turned on the camera",
"client_microphone_off": "The client has turned off the microphone",
"client_microphone_on": "The client has turned on the microphone",
"chat_history_deleted_by_client": "You have deleted the chat history",

"provider_joined": "Provider joined the consultation",
"provider_left": "The provider has left the consultation",
Expand Down
1 change: 1 addition & 0 deletions src/blocks/ActivityHistory/locales/kk.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"client_camera_on": "Клиент камераны қосты",
"client_microphone_off": "Клиент микрофонды өшірді",
"client_microphone_on": "Клиент микрофонды қосты",
"chat_history_deleted_by_client": "Сіз чат тарихын жойдыңыз",

"provider_joined": "Консультант консультацияға қосылды",
"provider_left": "Консультант консультациядан шықты",
Expand Down
1 change: 1 addition & 0 deletions src/blocks/ActivityHistory/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"client_camera_on": "Клиент включил камеру",
"client_microphone_off": "Клиент выключил микрофон",
"client_microphone_on": "Клиент включил микрофон",
"chat_history_deleted_by_client": "Вы удалили историю чата",

"provider_joined": "Консультант присоединился к консультации",
"provider_left": "Консультант покинул консультацию",
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/Consultations/Consultations.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Reac, { useState, useCallback, useMemo } from "react";
import { useState, useCallback, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { StyleSheet, View } from "react-native";

Expand Down
12 changes: 12 additions & 0 deletions src/blocks/UserDetails/UserDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const UserDetails = ({
openDeleteAccountBackdrop,
openSelectAvatarBackdrop,
openDeletePictureBackdrop,
openDeleteChatHistoryBackdrop,
navigation,
}) => {
const { t } = useTranslation("user-details");
Expand Down Expand Up @@ -458,6 +459,17 @@ export const UserDetails = ({
label={t("delete_account")}
type={"ghost"}
onPress={openDeleteAccountBackdrop}
style={styles.textButton}
/>
<ButtonWithIcon
iconName={"circle-actions-close"}
iconSize={"md"}
size="lg"
iconColor={"#eb5757"}
color={"red"}
label={t("delete_chat")}
type={"ghost"}
onPress={openDeleteChatHistoryBackdrop}
style={[styles.textButton, styles.marginBottom20]}
/>
</View>
Expand Down
1 change: 1 addition & 0 deletions src/blocks/UserDetails/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"change_password": "Change password",
"delete_account": "Delete account",
"logout": "Logout",
"delete_chat": "Clear chat history",

"dropdown_sex_label": "Gender",
"dropdown_year_label": "Year of birth",
Expand Down
1 change: 1 addition & 0 deletions src/blocks/UserDetails/locales/kk.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"change_password": "Құпия сөзді өзгерту",
"delete_account": "Аккаунтты жою",
"logout": "Шығу",
"delete_chat": "Чат тарихын тазалау",

"dropdown_sex_label": "Жынысы",
"dropdown_year_label": "Туған жылы",
Expand Down
1 change: 1 addition & 0 deletions src/blocks/UserDetails/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"change_password": "Изменить пароль",
"delete_account": "Удалить аккаунт",
"logout": "Выйти",
"delete_chat": "Очистить историю чата",

"dropdown_sex_label": "Пол",
"dropdown_year_label": "Год рождения",
Expand Down
2 changes: 2 additions & 0 deletions src/components/modals/TransparentModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function TransparentModal({
handleClose,
ctaLabel,
ctaHandleClick,
ctaColor = "green",
isCtaDisabled = false,
secondaryCtaLabel,
secondaryCtaHandleClick,
Expand Down Expand Up @@ -70,6 +71,7 @@ export function TransparentModal({
size="lg"
disabled={isCtaDisabled}
loading={isCtaLoading}
color={ctaColor}
/>
) : null}
{secondaryCtaLabel && (
Expand Down
57 changes: 57 additions & 0 deletions src/modals/DeleteChatHistory/DeleteChatHistory.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { useMutation } from "@tanstack/react-query";

import { TransparentModal } from "#components";
import { useError } from "#hooks";
import { showToast } from "#utils";
import { clientSvc } from "#services";

/**
* DeleteChatHistory
*
* The DeleteChatHistory modal
*
* @return {jsx}
*/
export const DeleteChatHistory = ({ isOpen, onClose }) => {
const { t } = useTranslation("delete-chat-history");

const [errors, setErrors] = useState({});

const deleteChat = async () => {
const res = await clientSvc.deleteChatHistory();
return res;
};

const deleteAccountMutation = useMutation(deleteChat, {
onSuccess: () => {
showToast({ message: t("success") });
onClose();
},
onError: (error) => {
const { message: errorMessage } = useError(error);
setErrors({ submit: errorMessage });
},
});

const handleConfirm = () => {
deleteAccountMutation.mutate();
};

return (
<TransparentModal
heading={t("heading")}
text={t("subheading")}
isOpen={isOpen}
handleClose={onClose}
ctaLabel={t("confirm")}
ctaColor="red"
ctaHandleClick={handleConfirm}
secondaryCtaLabel={t("cancel")}
secondaryCtaType="primary"
secondaryCtaHandleClick={onClose}
errorMessage={errors.submit}
/>
);
};
1 change: 1 addition & 0 deletions src/modals/DeleteChatHistory/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./DeleteChatHistory.jsx";
3 changes: 3 additions & 0 deletions src/modals/DeleteChatHistory/locales.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * as en from "./locales/en.json";
export * as ru from "./locales/ru.json";
export * as kk from "./locales/kk.json";
7 changes: 7 additions & 0 deletions src/modals/DeleteChatHistory/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"heading": "Are you sure you want to delete all your chat data?",
"subheading": "This action is irreversible.",
"confirm": "Yes, delete all my chat data",
"cancel": "No, keep my chat data",
"success": "Your chat data has been deleted successfully."
}
7 changes: 7 additions & 0 deletions src/modals/DeleteChatHistory/locales/kk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"heading": "Чат деректеріңіздің бәрін жою керек пе екеніне сенімдісіз бе?",
"subheading": "Бұл әрекетті болдырмауға болмайды.",
"confirm": "Иә, чат деректерімді бәрін жою",
"cancel": "Жоқ, чат деректерімді сақтау",
"success": "Сіздің чат деректеріңіз сәтті жойылды."
}
7 changes: 7 additions & 0 deletions src/modals/DeleteChatHistory/locales/ru.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"heading": "Вы уверены, что хотите удалить всю вашу историю чата?",
"subheading": "Это действие необратимо.",
"confirm": "Да, удалить всю мою историю чата",
"cancel": "Нет, сохранить мою историю чата",
"success": "Ваша история чата была успешно удалена."
}
1 change: 1 addition & 0 deletions src/modals/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from "./RequireDataAgreemant";
export * from "./MoodTrackerMoreInformation";
export * from "./PaymentInformation";
export * from "./HowItWorksMyQA";
export * from "./DeleteChatHistory";
1 change: 1 addition & 0 deletions src/modals/locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * as RequireDataAgreemant from "./RequireDataAgreemant/locales";
export * as MoodTrackerMoreInformation from "./MoodTrackerMoreInformation/locales";
export * as PaymentInformation from "./PaymentInformation/locales";
export * as HowItWorksMyQA from "./HowItWorksMyQA/locales";
export * as DeleteChatHistory from "./DeleteChatHistory/locales";
22 changes: 17 additions & 5 deletions src/screens/Consultation/Consultation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,25 @@ export const Consultation = ({ navigation, route }) => {
: false;
};

const chatDataQuery = useGetChatData(consultation?.chatId, (data) => {
const onGetChatDataSuccess = (data) => {
setIsProviderInSession(checkHasProviderJoined(data.messages));
setMessages((prev) => ({
...prev,
currentSession: data.messages,
}));
});
};

const chatDataQuery = useGetChatData(
consultation?.chatId,
onGetChatDataSuccess
);

const clientId = chatDataQuery.data?.clientDetailId;
const providerId = chatDataQuery.data?.providerDetailId;
const allChatHistoryQuery = useGetAllChatHistoryData(
providerId,
clientId,
true
chatDataQuery.isFetched
);

useEffect(() => {
Expand Down Expand Up @@ -204,16 +209,23 @@ export const Consultation = ({ navigation, route }) => {
useEffect(() => {
if (
allChatHistoryQuery.data?.messages &&
chatDataQuery.data?.messages &&
!messages.previousSessions.length
) {
setMessages((prev) => {
const currentMessagesTimes = chatDataQuery.data.messages.map(
(x) => x.time
);
const previousFiltered = allChatHistoryQuery.data.messages
.flat()
.filter((x) => !currentMessagesTimes.includes(x.time));
return {
...prev,
previousSessions: allChatHistoryQuery.data.messages,
previousSessions: previousFiltered,
};
});
}
}, [allChatHistoryQuery.data]);
}, [allChatHistoryQuery.data, chatDataQuery.data]);

useEffect(() => {
if (
Expand Down
1 change: 1 addition & 0 deletions src/screens/Consultation/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"provider_camera_on": "The provider has turned on the camera",
"provider_microphone_off": "The provider has turned off the microphone",
"provider_microphone_on": "The provider has turned on the microphone",
"chat_history_deleted_by_client": "You have deleted the chat history",

"send_message": "Type your message here...",
"show_system_messages": "Show system messages",
Expand Down
1 change: 1 addition & 0 deletions src/screens/Consultation/locales/kk.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"provider_camera_on": "Консультант камераны қосты",
"provider_microphone_off": "Консультант микрофонды өшірді",
"provider_microphone_on": "Консультант микрофонды қосты",
"chat_history_deleted_by_client": "Сіз чат тарихын жойдыңыз",

"send_message": "Хабарламаңызды осы жерге енгізіңіз...",
"show_system_messages": "Жүйелік хабарламаларды көрсету",
Expand Down
1 change: 1 addition & 0 deletions src/screens/Consultation/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"provider_camera_on": "Консультант включил камеру",
"provider_microphone_off": "Консультант отключил микрофон",
"provider_microphone_on": "Консультант включил микрофон",
"chat_history_deleted_by_client": "Вы удалили историю чата",

"send_message": "Введите Ваше сообщение здесь...",
"show_system_messages": "Показать системные сообщения",
Expand Down
14 changes: 14 additions & 0 deletions src/screens/UserDetails/UserDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
DeleteProfilePicture,
SelectAvatar,
} from "#backdrops";
import { DeleteChatHistory } from "#modals";

/**
* UserDetails
Expand All @@ -22,17 +23,25 @@ export const UserDetails = ({ navigation }) => {
useState(false);
const [isDeletePictureBackdropShown, setIsDeletePictureBackdropShown] =
useState(false);
const [
isDeleteChatHistoryBackdropShown,
setIsDeleteChatHistoryBackdropShown,
] = useState(false);

const openChangePasswordBackdrop = () => setIsChangePasswordOpen(true);
const openDeleteAccountBackdrop = () => setIsDeleteBackdropShown(true);
const openSelectAvatarBackdrop = () => setIsSelectAvatarBackdropShown(true);
const openDeletePictureBackdrop = () => setIsDeletePictureBackdropShown(true);
const openDeleteChatHistoryBackdrop = () =>
setIsDeleteChatHistoryBackdropShown(true);

const closeChangePasswordBackdrop = () => setIsChangePasswordOpen(false);
const closeDeleteAccountBackdrop = () => setIsDeleteBackdropShown(false);
const closeSelectAvatarBackdrop = () => setIsSelectAvatarBackdropShown(false);
const closeDeletePictureBackdrop = () =>
setIsDeletePictureBackdropShown(false);
const closeDeleteChatHistoryBackdrop = () =>
setIsDeleteChatHistoryBackdropShown(false);

return (
<Screen>
Expand All @@ -42,6 +51,7 @@ export const UserDetails = ({ navigation }) => {
openChangePasswordBackdrop={openChangePasswordBackdrop}
openSelectAvatarBackdrop={openSelectAvatarBackdrop}
openDeletePictureBackdrop={openDeletePictureBackdrop}
openDeleteChatHistoryBackdrop={openDeleteChatHistoryBackdrop}
/>
<SelectAvatar
isOpen={isSelectAvatarBackdropShown}
Expand All @@ -59,6 +69,10 @@ export const UserDetails = ({ navigation }) => {
isOpen={isDeletePictureBackdropShown}
onClose={closeDeletePictureBackdrop}
/>
<DeleteChatHistory
isOpen={isDeleteChatHistoryBackdropShown}
onClose={closeDeleteChatHistoryBackdrop}
/>
</Screen>
);
};
8 changes: 8 additions & 0 deletions src/services/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ async function addQuestionVote(answerId, vote) {
return response;
}

async function deleteChatHistory() {
const response = await http.put(`${API_ENDPOINT}/chat-history`, {
time: JSON.stringify(new Date().getTime()),
});
return response;
}

const exportedFunctions = {
addMoodTrack,
getClientData,
Expand All @@ -188,6 +195,7 @@ const exportedFunctions = {
getClientQuestions,
getQuestions,
addQuestionVote,
deleteChatHistory,
};

export default exportedFunctions;
Loading

0 comments on commit 02fdd7c

Please sign in to comment.