diff --git a/src/(apicalls)/accounts/account.tsx b/src/(apicalls)/accounts/account.tsx new file mode 100644 index 0000000..80df3ae --- /dev/null +++ b/src/(apicalls)/accounts/account.tsx @@ -0,0 +1,18 @@ +"use server"; +import { fetchData, fetchDataWithToken } from "../api-fetcher"; +import { baseUrl, FilterList, FilterListInterface } from "../basics"; + +const accountsListEndpoint = `${baseUrl}/account/records/list`; + +async function retrieveaccountsList(payload: FilterListInterface) { + const feedObject = new FilterList(payload); + const tokenResponse: any = await fetchDataWithToken( + accountsListEndpoint, + feedObject, + "POST", + false + ); + return tokenResponse; +} + +export { retrieveaccountsList }; diff --git a/src/(apicalls)/api-fetcher.tsx b/src/(apicalls)/api-fetcher.tsx index a86ec5d..34bae7a 100644 --- a/src/(apicalls)/api-fetcher.tsx +++ b/src/(apicalls)/api-fetcher.tsx @@ -30,7 +30,7 @@ const prepareResponse = async (response: any) => { const statusResponse = response?.status; const errorResponse = responseJson?.error || responseJson?.Error; const messageResponse = (responseJson?.message || "").toString(); - const completeResponse = responseJson?.completed; + const completeResponse = responseJson?.completed || false; const preparedResponse = { completed: completeResponse, diff --git a/src/(apicalls)/building/livingSpace.tsx b/src/(apicalls)/building/livingSpace.tsx new file mode 100644 index 0000000..4ea5af2 --- /dev/null +++ b/src/(apicalls)/building/livingSpace.tsx @@ -0,0 +1,18 @@ +"use server"; +import { fetchData, fetchDataWithToken } from "../api-fetcher"; +import { baseUrl, FilterList, FilterListInterface } from "../basics"; + +const livingSpaceListEndpoint = `${baseUrl}/building/living_space/list`; + +async function retrievelivingSpaceList(payload: FilterListInterface) { + const feedObject = new FilterList(payload); + const tokenResponse: any = await fetchDataWithToken( + livingSpaceListEndpoint, + feedObject, + "POST", + false + ); + return tokenResponse; +} + +export { retrievelivingSpaceList }; diff --git a/src/(apicalls)/login/login.tsx b/src/(apicalls)/login/login.tsx index c64741a..523767a 100644 --- a/src/(apicalls)/login/login.tsx +++ b/src/(apicalls)/login/login.tsx @@ -39,6 +39,7 @@ async function loginViaAccessKeys(payload: LoginViaAccessKeys) { "POST", false ); + if (tokenResponse.status === 200) { const accessToken = await nextCrypto.encrypt(tokenResponse.access_token); const accessObject = await nextCrypto.encrypt( diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index a1a14b2..dd34e90 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -15,6 +15,7 @@ const Dashboard: React.FC = async () => { redirect("/login/email"); } const eventsList = await retrieveAvailableEvents(); + console.log("eventsList", eventsList); const availableMenu = retrieveAvailableCategories(eventsList || []); return ( <> diff --git a/src/appEvents/account/account.tsx b/src/appEvents/account/account.tsx index e69de29..b7839a3 100644 --- a/src/appEvents/account/account.tsx +++ b/src/appEvents/account/account.tsx @@ -0,0 +1,5 @@ +import Account from "@/components/ContextComponents/Accounts/accountRecords"; + +const AccountPage = ; + +export default AccountPage; diff --git a/src/appEvents/building/livingspace.tsx b/src/appEvents/building/livingspace.tsx new file mode 100644 index 0000000..eb73ff5 --- /dev/null +++ b/src/appEvents/building/livingspace.tsx @@ -0,0 +1,5 @@ +import BuildLivingSpace from "@/components/ContextComponents/LivingSpace/LivingSpace"; + +const BuildLivingSpacePage = ; + +export default BuildLivingSpacePage; diff --git a/src/appEvents/categories.ts b/src/appEvents/categories.ts index 0d2847f..38a367c 100644 --- a/src/appEvents/categories.ts +++ b/src/appEvents/categories.ts @@ -5,9 +5,12 @@ import { BuildAreaIcon, } from "./building/iconSet"; import { AccountIcon, meetingIcon } from "./account/iconSet"; -import BuildPage from "./building/build"; import { InviteIcon, TaskIcon } from "./decisionBook/iconSet"; +import BuildPage from "./building/build"; +import BuildLivingSpacePage from "./building/livingspace"; +import AccountPage from "./account/account"; + const BuildSubCategories = [ { title: "Daireler", @@ -36,7 +39,7 @@ const BuildSubCategories = [ { title: "Yaşayan Kişiler", icon: LivingSpaceIcon, - component: BuildPage, + component: BuildLivingSpacePage, selfEndpoints: [ "/building/living_space/list", "/building/living_space/create", @@ -124,8 +127,8 @@ const LeftMenuCategories = [ subCategories: [ { title: "Bakiye Sorgulama", - icon: "balance", - component: BuildPage, + icon: AccountIcon, + component: AccountPage, subCategories: [], selfEndpoints: ["/account/records/list"], allEndpoints: [], diff --git a/src/components/ContextComponents/Accounts/accountRecords.tsx b/src/components/ContextComponents/Accounts/accountRecords.tsx new file mode 100644 index 0000000..58bba5e --- /dev/null +++ b/src/components/ContextComponents/Accounts/accountRecords.tsx @@ -0,0 +1,154 @@ +"use client"; +import React from "react"; +import EventButton from "@/components/ContextComponents/Commons/EventButton"; +import Table from "@/components/ContextComponents/Commons/Table"; + +import { retrieveAvailableEvents } from "@/(apicalls)/cookies/token"; +import { retrieveaccountsList } from "@/(apicalls)/accounts/account"; + +const Account: React.FC = () => { + const [renderTable, setRenderTable] = React.useState(false); + const [renderCreate, setRenderCreate] = React.useState(false); + const [renderUpdate, setRenderUpdate] = React.useState(false); + + const endpointNeeds = [ + { + endpoint: "/account/records/list", + component: setRenderTable, + }, + { + endpoint: "/account/records/create", + component: setRenderCreate, + }, + { + endpoint: "/account/records/update/{build_uu_id}", + component: setRenderUpdate, + }, + ]; + + React.useEffect(() => { + retrieveAvailableEvents() + .then((data) => { + for (const endpointNeed of endpointNeeds) { + if (data?.availableEvents.includes(endpointNeed.endpoint)) { + endpointNeed.component(true); + } + } + }) + .catch((error) => { + console.log("error", error); + }); + }, []); + + return ( + <> +
+ {renderUpdate && ( + console.log("Delete clicked")} + label="Seçili Olanları Sil" + bgColor="bg-emerald-700" + icon={ + + + + + + + } + /> + )} + {renderUpdate && ( + console.log("Create clicked")} + label="Kayıdı Güncelle" + bgColor="bg-blue-500" + icon={ + + + + + + + } + /> + )} + {renderCreate && ( + console.log("Create clicked")} + label="Kayıt ekle" + bgColor="bg-indigo-700" + icon={ + + + + + + + } + /> + )} +
+ {renderTable ? : <>} + + ); +}; + +export default Account; diff --git a/src/components/ContextComponents/Commons/Table.tsx b/src/components/ContextComponents/Commons/Table.tsx index 7bd619f..ccd3898 100644 --- a/src/components/ContextComponents/Commons/Table.tsx +++ b/src/components/ContextComponents/Commons/Table.tsx @@ -22,6 +22,7 @@ const formSchema = z.object({ }); const Table: React.FC = ({ createTable }) => { + const [initalData, setInitalData] = React.useState([]); const [tabledata, settabledata] = React.useState([]); const [headersList, setHeadersList] = React.useState([]); const form = useForm>({ @@ -32,6 +33,7 @@ const Table: React.FC = ({ createTable }) => { createTable({}).then((res: Object) => { const resData: any = res?.data || []; settabledata(resData || []); + setInitalData(resData || []); setHeadersList(getHeaders(resData)); }); }, []); @@ -64,229 +66,133 @@ const Table: React.FC = ({ createTable }) => { function cleanSearch() { form.setValue("searchText", ""); - settabledata(Array.from(data)); + settabledata(Array.from(initalData)); } function search(values: z.infer) { const searchText = values.searchText; if (searchText === "") { - settabledata(Array.from(data)); + settabledata(Array.from(initalData)); } else { - const filteredList = Array.from(data).filter((item) => { - return item.name.toLowerCase().includes(searchText.toLowerCase()); + const filteredList = Array.from(tabledata).filter((item) => { + Array.from(item).map((row) => { + console.log(row); + return row.toLowerCase().includes(searchText.toLowerCase()); + }); }); + console.log("filteredList", filteredList); settabledata(filteredList); } } return ( <> -
-
-
cleanSelection()} - > - - - - - - - - - Seçimleri Temizle -
-
-
-
- - - - - - - - - Seçili Olanları Sil -
-
-
-
- - - - - - - - - Kayıdı Güncelle -
-
-
-
- - - - - - - - - Kayıt ekle -
-
-
-
-
- +
cleanSelection()} > -
- ( - - - - - - - )} - /> -
+
+
+ + +
+ ( + + + + + + + )} + /> + - + -
- - + + + + + +
+ + +
diff --git a/src/components/ContextComponents/LivingSpace/LivingSpace.tsx b/src/components/ContextComponents/LivingSpace/LivingSpace.tsx index e69de29..f509cdc 100644 --- a/src/components/ContextComponents/LivingSpace/LivingSpace.tsx +++ b/src/components/ContextComponents/LivingSpace/LivingSpace.tsx @@ -0,0 +1,155 @@ +"use client"; +import React from "react"; +import EventButton from "@/components/ContextComponents/Commons/EventButton"; +import Table from "@/components/ContextComponents/Commons/Table"; + +import { retrieveAvailableEvents } from "@/(apicalls)/cookies/token"; +import { retrievelivingSpaceList } from "@/(apicalls)/building/livingSpace"; + +const BuildLivingSpace: React.FC = () => { + const [renderTable, setRenderTable] = React.useState(false); + const [renderCreate, setRenderCreate] = React.useState(false); + const [renderUpdate, setRenderUpdate] = React.useState(false); + const [renderDelete, setRenderDelete] = React.useState(false); + + const endpointNeeds = [ + { + endpoint: "/building/living_space/list", + component: setRenderTable, + }, + { + endpoint: "/building/living_space/create", + component: setRenderCreate, + }, + { + endpoint: "/building/living_space/update/{build_uu_id}", + component: setRenderUpdate, + }, + ]; + + React.useEffect(() => { + retrieveAvailableEvents() + .then((data) => { + for (const endpointNeed of endpointNeeds) { + if (data?.availableEvents.includes(endpointNeed.endpoint)) { + endpointNeed.component(true); + } + } + }) + .catch((error) => { + console.log("error", error); + }); + }, []); + + return ( + <> +
+ {renderDelete && ( + console.log("Delete clicked")} + label="Seçili Olanları Sil" + bgColor="bg-emerald-700" + icon={ + + + + + + + } + /> + )} + {renderUpdate && ( + console.log("Create clicked")} + label="Kayıdı Güncelle" + bgColor="bg-blue-500" + icon={ + + + + + + + } + /> + )} + {renderCreate && ( + console.log("Create clicked")} + label="Kayıt ekle" + bgColor="bg-indigo-700" + icon={ + + + + + + + } + /> + )} +
+ {renderTable ?
: <>} + + ); +}; + +export default BuildLivingSpace; diff --git a/src/components/Sidebar/SidebarItem.tsx b/src/components/Sidebar/SidebarItem.tsx index 9128ad0..e57c1d1 100644 --- a/src/components/Sidebar/SidebarItem.tsx +++ b/src/components/Sidebar/SidebarItem.tsx @@ -28,7 +28,7 @@ const SidebarItem = ({ }; const isActive = (item: any) => { - if (item.children) { + if (item.title === pageName?.title) { return item.children.some((child: any) => isActive(child)); } return false; @@ -37,15 +37,18 @@ const SidebarItem = ({ const isItemActive = isActive(item); return ( -
- {item.icon} - {item.title} -
+ <> +

{item.title}

+
+ {item.icon} + {item.title} +
+ ); }; diff --git a/src/components/login/loginselectemployee.tsx b/src/components/login/loginselectemployee.tsx index e148171..757ff2c 100644 --- a/src/components/login/loginselectemployee.tsx +++ b/src/components/login/loginselectemployee.tsx @@ -23,7 +23,6 @@ const LoginSelectEmployee: React.FC = ({ company_list }) => { setIsLoading(true); loginSelectEmployee({ company_uu_id: data?.uu_id }) .then((responseData: any) => { - console.log("responseData", responseData); if (responseData?.completed) { showToast(toast, "Şirket seçimi", { message: "Şirket seçimi başarılı", diff --git a/src/components/login/loginselectoccupant.tsx b/src/components/login/loginselectoccupant.tsx index b8e2c46..5ff98bd 100644 --- a/src/components/login/loginselectoccupant.tsx +++ b/src/components/login/loginselectoccupant.tsx @@ -35,7 +35,6 @@ const LoginSelectOccupant: React.FC = ({ occupant_uu_id: data?.uu_id, }) .then((responseData: any) => { - console.log("occupant", responseData); if (responseData?.completed) { showToast(toast, "Şirket seçimi", { message: "Şirket seçimi başarılı", diff --git a/src/components/login/loginwithemail.tsx b/src/components/login/loginwithemail.tsx index 2f4a2e6..5135cbb 100644 --- a/src/components/login/loginwithemail.tsx +++ b/src/components/login/loginwithemail.tsx @@ -71,6 +71,7 @@ const LoginWithEmail: React.FC = () => { message: res?.message, data: res, }); + setIsLoading(false); } }) .catch((error) => { @@ -79,6 +80,7 @@ const LoginWithEmail: React.FC = () => { message: "Kullanıcı adı veya şifre hatalı", data: JSON.stringify(error.code), }); + setIsLoading(false); }); } if (isLoading) {