Skip to content

Commit

Permalink
Merge pull request #294 from virtualidentityag/feat/group-chat-consul…
Browse files Browse the repository at this point in the history
…tant

Feat/group chat consultant
  • Loading branch information
web-mi authored Oct 4, 2023
2 parents d5845f8 + 17b6949 commit de284fc
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/api/counselor/addCounselorData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { putAgenciesForCounselor } from '../agency/putAgenciesForCounselor';
* @return data
*/
export const addCounselorData = (counselorData: Record<string, any>): Promise<CounselorData> => {
const { firstname, lastname, formalLanguage, email, absent, username, twoFactorAuth } = counselorData;
const { firstname, lastname, formalLanguage, email, absent, username, twoFactorAuth, isGroupchatConsultant } =
counselorData;

// just use needed data from whole form data
const strippedCounselor = {
Expand All @@ -21,14 +22,15 @@ export const addCounselorData = (counselorData: Record<string, any>): Promise<Co
absent: !!absent,
username: encodeUsername(username),
twoFactorAuth,
isGroupchatConsultant,
};

return (
fetchData({
url: counselorEndpoint,
method: FETCH_METHODS.POST,
skipAuth: false,
responseHandling: [FETCH_ERRORS.CONFLICT, FETCH_ERRORS.CONFLICT_WITH_RESPONSE],
responseHandling: [FETCH_ERRORS.CONFLICT, FETCH_ERRORS.CONFLICT_WITH_RESPONSE, FETCH_ERRORS.CATCH_ALL],
bodyData: JSON.stringify(strippedCounselor),
})
.then((response) => {
Expand Down
13 changes: 12 additions & 1 deletion src/api/counselor/editCounselorData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ import { putAgenciesForCounselor } from '../agency/putAgenciesForCounselor';
* @return data
*/
export const editCounselorData = async (id: string, formData: CounselorData): Promise<CounselorData> => {
const { firstname, lastname, formalLanguage, email, absent, username, absenceMessage, twoFactorAuth } = formData;
const {
firstname,
lastname,
formalLanguage,
email,
absent,
username,
absenceMessage,
twoFactorAuth,
isGroupchatConsultant,
} = formData;

// just use needed data from whole form data
const strippedCounselor = {
Expand All @@ -24,6 +34,7 @@ export const editCounselorData = async (id: string, formData: CounselorData): Pr
username: encodeUsername(username),
...(absent ? { absenceMessage } : {}),
twoFactorAuth,
isGroupchatConsultant,
};

const ids = ((formData.agencies as LabeledValue[])?.map(({ value }) => value) || []) as string[];
Expand Down
4 changes: 4 additions & 0 deletions src/context/FeatureContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ const FeatureProvider = ({ children, tenantData, publicTenantData }: FeatureProv
name: FeatureFlag.ConsultingTypesForAgencies,
active: !!featureFlags.useConsultingTypesForAgencies,
},
{
name: FeatureFlag.GroupChatV2,
active: !!publicTenantData?.settings.featureGroupChatV2Enabled,
},
]);

return <FeatureContext.Provider value={state}>{children}</FeatureContext.Provider>;
Expand Down
1 change: 1 addition & 0 deletions src/enums/FeatureFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export enum FeatureFlag {
Topics = 'topics',
TopicsInRegistration = 'topicsInRegistration',
ConsultingTypesForAgencies = 'consultingTypesForAgencies',
GroupChatV2 = 'featureGroupChatV2Enabled',
}
1 change: 1 addition & 0 deletions src/locales/de/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@
"counselor.formalLanguage": "Formale Sprache",
"counselor.absent": "Abwesend",
"counselor.absenceMessage": "Abwesenheitsnotiz",
"counselor.isGroupChatConsultant": "Dem Benutzer erlauben, Gruppenchats zu erstellen",
"counselor.title.text": "Erstellen und bearbeiten Sie Daten Ihrer Berater",
"counselor.modal.headline.delete": "Nutzer wirklich löschen",
"counselor.modal.headline.edit": "Berater bearbeiten",
Expand Down
22 changes: 15 additions & 7 deletions src/pages/Statistic.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FileDownloadOutlined } from '@mui/icons-material';
import { Col, Row } from 'antd';
import { Col, Row, Spin } from 'antd';
import { useEffect, useState } from 'react';
import { CSVLink } from 'react-csv';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -93,12 +93,20 @@ export const Statistic = () => {
<div className="statistic__headline">{t('statistic.title.text')}</div>
<div className="statistic__download">{t('statistic.download.text')}</div>
<div className="statistic__download">
<CSVLink separator=";" data={csvData} filename={`${t('statistic.download.filename')}.csv`}>
<span className="statistic__icon">
<FileDownloadOutlined />
</span>
<span className="statistic__text">{t('statistic.download.link')}</span>
</CSVLink>{' '}
{isRequestInProgress ? (
<Spin />
) : (
<CSVLink
separator=";"
data={csvData}
filename={`${t('statistic.download.filename')}.csv`}
>
<span className="statistic__icon">
<FileDownloadOutlined />
</span>
<span className="statistic__text">{t('statistic.download.link')}</span>
</CSVLink>
)}
</div>
</div>
</Col>
Expand Down
10 changes: 10 additions & 0 deletions src/pages/users/Edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ import { useUserPermissions } from '../../../hooks/useUserPermission';
import { convertToOptions } from '../../../utils/convertToOptions';
import { decodeUsername } from '../../../utils/encryptionHelpers';
import { FormSwitchField } from '../../../components/FormSwitchField';
import { useFeatureContext } from '../../../context/FeatureContext';
import { FeatureFlag } from '../../../enums/FeatureFlag';

export const UserEditOrAdd = () => {
const navigate = useNavigate();
const [form] = useForm();
const { can } = useUserPermissions();
const { t } = useTranslation();
const { isEnabled } = useFeatureContext();
const { typeOfUsers, id } = useParams<{ id: string; typeOfUsers: TypeOfUser }>();
const { data: consultantsResponse, isLoading: isLoadingConsultants } = useConsultantsOrAdminsData({
search: id,
Expand Down Expand Up @@ -92,6 +95,7 @@ export const UserEditOrAdd = () => {
initialValues={{
...(singleData || {
formalLanguage: true,
isGroupchatConsultant: isEnabled(FeatureFlag.GroupChatV2),
}),
username: decodeUsername(singleData?.username || ''),
agencies: convertToOptions(singleData?.agencies || [], ['postcode', 'name', 'city'], 'id'),
Expand Down Expand Up @@ -142,6 +146,12 @@ export const UserEditOrAdd = () => {
<Space align="center">
<FormSwitchField labelKey="counselor.formalLanguage" name="formalLanguage" />
{isEditing && <FormSwitchField labelKey="counselor.absent" name="absent" />}
{isEnabled(FeatureFlag.GroupChatV2) && (
<FormSwitchField
labelKey="counselor.isGroupChatConsultant"
name="isGroupchatConsultant"
/>
)}
</Space>
{isAbsentEnabled && (
<FormTextAreaField labelKey="counselor.absenceMessage" name="absenceMessage" />
Expand Down
1 change: 1 addition & 0 deletions src/types/counselor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export interface CounselorData {
deleteDate?: string;
status: Status;
twoFactorAuth?: boolean;
isGroupchatConsultant?: boolean;
}
1 change: 1 addition & 0 deletions src/types/tenant.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface BasicTenantData {
featureTopicsEnabled?: boolean | null;
topicsInRegistrationEnabled?: boolean | null;
featureStatisticsEnabled?: boolean;
featureGroupChatV2Enabled?: boolean;
};
}

Expand Down

0 comments on commit de284fc

Please sign in to comment.