-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d52f87
commit 65a1024
Showing
11 changed files
with
269 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
import React, { useEffect, useMemo, useState } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { toast } from "react-toastify"; | ||
|
||
import { | ||
Block, | ||
BaseTable, | ||
Loading, | ||
Modal, | ||
Input, | ||
} from "@USupport-components-library/src"; | ||
import { useGetOrganizationsWithDetails, useEditOrganization } from "#hooks"; | ||
|
||
import "./organizations.scss"; | ||
import { useQueryClient } from "@tanstack/react-query"; | ||
import useCreateOrganization from "../../hooks/useCreateOrganization"; | ||
|
||
/** | ||
* Organizations | ||
* | ||
* Organizations | ||
* | ||
* @return {jsx} | ||
*/ | ||
export const Organizations = () => { | ||
const queryClient = useQueryClient(); | ||
const { t, i18n } = useTranslation("organizations"); | ||
|
||
const { data, isLoading } = useGetOrganizationsWithDetails(); | ||
|
||
const [dataToDisplay, setDataToDisplay] = useState(); | ||
const [isModalOpen, setIsModalOpen] = useState(false); | ||
const [organizationToEdit, setOrganizationToEdit] = useState(); | ||
const [newOrganizationName, setNewOrganizationName] = useState(""); | ||
|
||
useEffect(() => { | ||
if (data) { | ||
setDataToDisplay(data); | ||
} | ||
}, [data]); | ||
|
||
const rows = useMemo(() => { | ||
return [ | ||
{ label: t("name"), sortingKey: "name" }, | ||
{ label: t("unique_providers"), sortingKey: "uniqueProviders" }, | ||
{ label: t("unique_clients"), sortingKey: "uniqueClients" }, | ||
{ label: t("total_consultations"), sortingKey: "totalConsultations" }, | ||
]; | ||
}, [i18n.language]); | ||
|
||
const rowsData = useMemo(() => { | ||
return dataToDisplay?.map((item) => { | ||
return [ | ||
<p className="text">{item.name}</p>, | ||
<p className="text centered">{item.uniqueProviders}</p>, | ||
<p className="text centered">{item.uniqueClients}</p>, | ||
<p className="text centered">{item.totalConsultations}</p>, | ||
]; | ||
}); | ||
}, [dataToDisplay]); | ||
|
||
const menuOptions = [ | ||
{ | ||
icon: "view", | ||
text: t("view"), | ||
handleClick: (id) => navigate(`/sponsor-details?sponsorId=${id}`), | ||
}, | ||
{ | ||
icon: "edit", | ||
text: t("edit"), | ||
handleClick: (id) => { | ||
console.log(id, "id"); | ||
setOrganizationToEdit(data.find((item) => item.organizationId === id)); | ||
setIsModalOpen(true); | ||
}, | ||
}, | ||
]; | ||
|
||
const onEditSuccess = () => { | ||
toast.success(t("organization_edited")); | ||
setIsModalOpen(false); | ||
setOrganizationToEdit(null); | ||
queryClient.invalidateQueries({ | ||
queryKey: ["GetOrganizationsWithDetails"], | ||
}); | ||
}; | ||
const onEditError = () => {}; | ||
const editOrganizationMutation = useEditOrganization( | ||
onEditSuccess, | ||
onEditError | ||
); | ||
|
||
const onCreateSuccess = () => { | ||
toast.success(t("organization_added")); | ||
setIsModalOpen(false); | ||
setNewOrganizationName(""); | ||
queryClient.invalidateQueries({ | ||
queryKey: ["GetOrganizationsWithDetails"], | ||
}); | ||
}; | ||
|
||
const onCreateError = () => {}; | ||
const createOrganizationMutation = useCreateOrganization( | ||
onCreateSuccess, | ||
onCreateError | ||
); | ||
|
||
const addOrganization = () => { | ||
createOrganizationMutation.mutate({ name: newOrganizationName }); | ||
}; | ||
const editOrganization = () => { | ||
editOrganizationMutation.mutate({ | ||
name: organizationToEdit.name, | ||
organizationId: organizationToEdit.organizationId, | ||
}); | ||
}; | ||
|
||
console.log(organizationToEdit); | ||
return ( | ||
<React.Fragment> | ||
<Modal | ||
isOpen={isModalOpen} | ||
heading={t( | ||
organizationToEdit ? "edit_organization" : "create_organization" | ||
)} | ||
closeModal={() => setIsModalOpen(false)} | ||
classes="organizations" | ||
ctaLabel={organizationToEdit ? t("save") : t("add")} | ||
ctaHandleClick={organizationToEdit ? editOrganization : addOrganization} | ||
isCtaLoading={ | ||
editOrganizationMutation.isLoading || | ||
createOrganizationMutation.isLoading | ||
} | ||
> | ||
<div className="organizations__modal"> | ||
<Input | ||
label={t("name")} | ||
value={ | ||
organizationToEdit ? organizationToEdit.name : newOrganizationName | ||
} | ||
onChange={(e) => { | ||
if (organizationToEdit) { | ||
setOrganizationToEdit((prev) => ({ | ||
...prev, | ||
name: e.target.value, | ||
})); | ||
} else { | ||
setNewOrganizationName(e.target.value); | ||
} | ||
}} | ||
/> | ||
</div> | ||
</Modal> | ||
|
||
<Block classes="organizations"> | ||
{isLoading ? ( | ||
<Loading /> | ||
) : ( | ||
<BaseTable | ||
data={data} | ||
rows={rows} | ||
rowsData={rowsData} | ||
handleClickPropName="organizationId" | ||
updateData={setDataToDisplay} | ||
menuOptions={menuOptions} | ||
buttonLabel={t("add_button")} | ||
buttonAction={() => setIsModalOpen(true)} | ||
// secondaryButtonLabel={t("filter_button")} | ||
t={t} | ||
/> | ||
)} | ||
</Block> | ||
</React.Fragment> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Organizations.jsx'; | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * as en from './locales/en.json'; | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "Name", | ||
"total_consultations": "Total consultations", | ||
"unique_providers": "Total providers", | ||
"unique_clients": "Total clients", | ||
"add_button": "Add organization", | ||
"filter_button": "Filter", | ||
"view": "View", | ||
"edit": "Edit", | ||
"save": "Save", | ||
"add": "Create", | ||
"edit_organization": "Edit organization", | ||
"create_organization": "Create organization", | ||
"organization_added": "Organization created", | ||
"organization_updated": "Organization updated" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "Атауы", | ||
"total_consultations": "Барлық кеңестер", | ||
"unique_providers": "Барлық провайдерлер", | ||
"unique_clients": "Барлық клиенттер", | ||
"add_button": "Ұйым қосу", | ||
"filter_button": "Сүзу", | ||
"view": "Көру", | ||
"edit": "Өңдеу", | ||
"save": "Сақтау", | ||
"add": "Жасау", | ||
"edit_organization": "Ұйымды өңдеу", | ||
"create_organization": "Ұйым жасау", | ||
"organization_added": "Ұйым құрылды", | ||
"organization_updated": "Ұйым жаңартылды" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "Nazwa", | ||
"total_consultations": "Łączna liczba konsultacji", | ||
"unique_providers": "Łączna liczba dostawców", | ||
"unique_clients": "Łączna liczba klientów", | ||
"add_button": "Dodaj organizację", | ||
"filter_button": "Filtruj", | ||
"view": "Zobacz", | ||
"edit": "Edytuj", | ||
"save": "Zapisz", | ||
"add": "Utwórz", | ||
"edit_organization": "Edytuj organizację", | ||
"create_organization": "Utwórz organizację", | ||
"organization_added": "Organizacja została utworzona", | ||
"organization_updated": "Organizacja została zaktualizowana" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "Название", | ||
"total_consultations": "Всего консультаций", | ||
"unique_providers": "Всего провайдеров", | ||
"unique_clients": "Всего клиентов", | ||
"add_button": "Добавить организацию", | ||
"filter_button": "Фильтр", | ||
"view": "Просмотр", | ||
"edit": "Редактировать", | ||
"save": "Сохранить", | ||
"add": "Создать", | ||
"edit_organization": "Редактировать организацию", | ||
"create_organization": "Создать организацию", | ||
"organization_added": "Организация создана", | ||
"organization_updated": "Организация обновлена" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "Назва", | ||
"total_consultations": "Всього консультацій", | ||
"unique_providers": "Всього провайдерів", | ||
"unique_clients": "Всього клієнтів", | ||
"add_button": "Додати організацію", | ||
"filter_button": "Фільтр", | ||
"view": "Переглянути", | ||
"edit": "Редагувати", | ||
"save": "Зберегти", | ||
"add": "Створити", | ||
"edit_organization": "Редагувати організацію", | ||
"create_organization": "Створити організацію", | ||
"organization_added": "Організацію створено", | ||
"organization_updated": "Організацію оновлено" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@import "@USupport-components-library/styles"; | ||
|
||
.organizations { | ||
&__modal { | ||
& .input-container { | ||
margin-block: 1rem; | ||
margin-left: 1rem; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters