Add 'sge-frontend/' from commit '5fa787e054b25ac53edc7ff0275ea7960a709401'

git-subtree-dir: sge-frontend
git-subtree-mainline: 876c278ac4
git-subtree-split: 5fa787e054
This commit is contained in:
2025-08-04 00:27:23 +03:00
337 changed files with 854877 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
import jwtDecode from "jwt-decode";
import ApplicationService from "../../../services/ApplicationService";
const refreshToken = localStorage.getItem("refreshToken");
export const newAccessToken = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query:
`
mutation {
refreshToken(input: { refreshToken: "` +
refreshToken +
`" }) {
accessToken
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const newAccessToken = response.data.data.refreshToken.accessToken;
const decodenewAccessToken = jwtDecode(newAccessToken);
localStorage.setItem("accessToken", newAccessToken);
localStorage.setItem("accessTokenExp", decodenewAccessToken.exp);
dispatch({
type: "GET_NEWACCESSTOKEN",
payload: {
newAccessToken,
},
});
});
};
};

View File

@@ -0,0 +1,208 @@
import ApplicationService from "../../../services/ApplicationService";
export const getAnswers = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
answers {
id
value
answer
isDefault
isDeleted
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const answers1 = response.data.data.answers;
const answers = answers1.filter((answer) => answer.isDeleted != true);
dispatch({
type: "GET_ANSWERS",
payload: {
answers,
},
});
});
};
};
export const getAnswersWithPaginate = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
paginateAnswers(
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
data.rowsPerPage
} }
criteria:{deleted:false}
sortBy: [{ direction: ASC, field: "value" }]
) {
pageInfo {
totalElements
totalPages
numberOfElements
pageNumber
pageSize
}
content {
id
value
answer
isDefault
isDeleted
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const answersWithPaginate = response?.data?.data?.paginateAnswers;
dispatch({
type: "GET_ANSWERS_WITH_PAGINATE",
payload: {
answersWithPaginate,
},
});
});
};
};
export const addAnswer = (data) => {
const dataToJSON = JSON.stringify(data);
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
mutation {
addAnswer(
input: ${deleteQuotesFromKey} )
{
id
value
answer
isDefault
isDeleted
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "ADD_ANSWER",
payload: {
answers: response.data.data.addAnswer,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const updateAnswer = (data) => {
let deleteIdFromData = { ...data };
delete deleteIdFromData.id;
const dataToJSON = JSON.stringify(deleteIdFromData);
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query:
`
mutation {
updateAnswer(id: "` +
data.id +
`", input: ${deleteQuotesFromKey}) {
id
value
answer
isDeleted
isDefault
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "UPDATE_ANSWER",
payload: {
answers: response.data.data.updateAnswer,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const deleteAnswer = (id) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `mutation {
deleteAnswer(id:"${id}")
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then(() => {
dispatch({
type: "DELETE_ANSWER",
payload: {
id: id,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};

View File

@@ -0,0 +1,553 @@
import ApplicationService from "../../../services/ApplicationService";
export const getAreas = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
areas {
id
tag
isDeleted
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const areas1 = response?.data?.data?.areas;
const areas = areas1?.filter((area) => area.isDeleted != true) || [];
dispatch({
type: "GET_AREAS",
payload: {
areas,
},
});
})
.catch((error) => {
console.error("Error fetching areas:", error);
dispatch({
type: "GET_AREAS",
payload: {
areas: [],
},
});
});
};
};
export const getAreasWithPaginate = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
paginateAreas(
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
data.rowsPerPage
} }
criteria: { deleted:false }
sortBy: [{ direction: ASC, field: "tag" }]
) {
pageInfo {
totalElements
totalPages
numberOfElements
pageNumber
pageSize
}
content {
id
tag
countries
{
id
countryCode
name
}
cities{
id
name
country{
id
name
}
}
districts{
id
name
city{
id
name
country{
id
name
}
}
}
neighborhoods{
id
name
district{
id
name
city{
id
name
country{
id
name
}
}
}
}
isDeleted
defaultArea
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const areasWithPaginate = response?.data?.data?.paginateAreas;
dispatch({
type: "GET_AREAS_WITH_PAGINATE",
payload: {
areasWithPaginate,
},
});
});
};
};
export const getAreasWithCriteria = (organizationId) => {
return async (dispatch) => {
// Don't make the request if organizationId is undefined, null, or empty
if (!organizationId || organizationId === "undefined") {
dispatch({
type: "GET_AREAS_WITH_CRITERIA",
payload: {
getAreasWithCriteria: [],
},
});
return;
}
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
areas(
criteria: { organizations:"${organizationId}" }
) {
id
tag
countries {
id
countryCode
name
}
cities {
id
name
coordinates
country{
id
name
}
}
districts {
id
name
coordinates
city{
id
name
country{
id
name
}
}
}
neighborhoods {
id
name
minLong
maxLong
minLat
maxLat
district{
id
name
city{
id
name
country{
id
name
}
}
}
}
isDeleted
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const areas1 = response?.data?.data?.areas;
const getAreasWithCriteria = areas1?.filter(
(area) => area.isDeleted != true
) || [];
dispatch({
type: "GET_AREAS_WITH_CRITERIA",
payload: {
getAreasWithCriteria,
},
});
})
.catch((error) => {
console.error("Error fetching areas with criteria:", error);
dispatch({
type: "GET_AREAS_WITH_CRITERIA",
payload: {
getAreasWithCriteria: [],
},
});
});
};
};
export const getAreasByDataCenter = (dataCenterId) => {
return async (dispatch) => {
// Don't make the request if dataCenterId is undefined, null, or empty
if (!dataCenterId || dataCenterId === "undefined") {
dispatch({
type: "GET_AREAS_WITH_CRITERIA",
payload: {
getAreasWithCriteria: [],
},
});
return;
}
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
dataCenter(id: "${dataCenterId}") {
id
dataCenter
area {
id
tag
countries {
id
countryCode
name
}
cities {
id
name
coordinates
country{
id
name
}
}
districts {
id
name
coordinates
city{
id
name
country{
id
name
}
}
}
neighborhoods {
id
name
minLong
maxLong
minLat
maxLat
district{
id
name
city{
id
name
country{
id
name
}
}
}
}
isDeleted
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const dataCenter = response?.data?.data?.dataCenter;
let areas = [];
if (dataCenter && dataCenter.area && !dataCenter.area.isDeleted) {
areas = [dataCenter.area];
}
dispatch({
type: "GET_AREAS_WITH_CRITERIA",
payload: {
getAreasWithCriteria: areas,
},
});
})
.catch((error) => {
console.error("Error fetching areas by data center:", error);
dispatch({
type: "GET_AREAS_WITH_CRITERIA",
payload: {
getAreasWithCriteria: [],
},
});
});
};
};
export const addArea = (data) => {
const dataToJSON = JSON.stringify(data);
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
mutation {
createArea(
input: ${deleteQuotesFromKey} )
{
id
tag
countries {
id
countryCode
name
}
cities {
id
name
country{
id
name
}
}
districts {
id
name
city{
id
name
country{
id
name
}
}
}
neighborhoods {
id
name
district{
id
name
city{
id
name
country{
id
name
}
}
}
}
isDeleted
defaultArea
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "ADD_AREA",
payload: {
areas: response.data.data.createArea,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const updateArea = (data) => {
let deleteIdFromData = { ...data };
delete deleteIdFromData.id;
const dataToJSON = JSON.stringify(deleteIdFromData);
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query:
`
mutation {
updateArea(id: "` +
data.id +
`", input: ${deleteQuotesFromKey}) {
id
tag
countries {
id
countryCode
name
}
cities {
id
name
country{
id
name
}
}
districts {
id
name
city{
id
name
country{
id
name
}
}
}
neighborhoods {
id
name
district{
id
name
city{
id
name
country{
id
name
}
}
}
}
isDeleted
defaultArea
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "UPDATE_AREA",
payload: {
areas: response.data.data.updateArea,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const deleteArea = (id) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `mutation {
deleteArea(id:"${id}")
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then(() => {
dispatch({
type: "DELETE_AREA",
payload: {
id: id,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};

View File

@@ -0,0 +1,117 @@
import ApplicationService from "../../../services/ApplicationService";
import jwtDecode from "jwt-decode";
export const handleLogin = (email, password) => async (dispatch) => {
try {
const res = await ApplicationService.httpWithoutAuthorization().post(
"/graphql",
{
query:
`
mutation {
login(input: { email: "` +
email +
`", password: "` +
password +
`" }) {
accessToken
email
user {
id
firstName
lastName
email
role{
id
tag
permissions{
tag
}
}
organizations{
id
tag
}
}
}
}
`,
}
);
const data = res.data;
dispatch({
type: "LOGIN",
payload: res.data.data,
});
localStorage.setItem("accessToken", data.data.login.accessToken);
// localStorage.setItem("refreshToken", res.data.data.login.refreshToken);
localStorage.setItem("userId", res.data.data.login.user.id);
localStorage.setItem("roleId", res.data.data.login.user.role.id);
localStorage.setItem("roleTag", res.data.data.login.user.role.tag);
localStorage.setItem(
"organizationId",
res.data.data.login.user.organizations?.[0]?.id
);
localStorage.setItem(
"organizationName",
res.data.data.login.user.organizations?.[0]?.tag
);
localStorage.setItem(
"currentUser",
data.data.login.user.firstName + " " + data.data.login.user.lastName
);
localStorage.setItem(
"permissions",
JSON.stringify(data.data.login.user.role.permissions)
);
const token = jwtDecode(data.data.login.accessToken);
localStorage.setItem("accessTokenExp", token.exp);
return data.data.login;
} catch (error) {
console.log("error: ", error);
if (error.message !== "Bu hesap için yetkiniz yok.") {
error.message = "Kullanıcı bilgileri hatalıdır. Lütfen tekrar deneyiniz.";
}
throw error;
}
};
// export const handleLogout = () => {
// return (dispatch) => {
// dispatch({
// type: "LOGOUT",
// });
// localStorage.clear();
// };
// };
export const handleLogout = () => async (dispatch) => {
try {
// const res = await ApplicationService.httpWithoutAuthorization().post(
// "/graphql",
// {
// query: `
// mutation {
// logout(input:{refreshToken:"${localStorage.getItem("refreshToken")}"})
// }
// `,
// },
// {
// headers: {
// Authorization: "Bearer " + localStorage.getItem("accessToken"),
// },
// }
// );
dispatch({
type: "LOGOUT",
});
localStorage.clear();
window.location.reload();
} catch (error) {
console.log("error: ", error);
throw error;
}
};

View File

@@ -0,0 +1,126 @@
import ApplicationService from "../../../services/ApplicationService";
export const getCities = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
cities (sortBy: [{ direction: ASC, field: "name" }]) {
id
name
country {
id
countryCode
name
}
coordinates
isDeleted
defaultCity
mainDataTables {
id
year
totalEmission
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const cities = response.data.data.cities;
dispatch({
type: "GET_CITIES",
payload: {
cities,
},
});
});
};
};
export const paginateCities = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
paginateCities(
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
data.rowsPerPage
} }
sortBy: [{ direction: ASC, field: "name" }]
) {
pageInfo {
totalElements
}
content {
id
name
country{
name
}
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const paginateCities = response.data.data.paginateCities;
dispatch({
type: "PAGINATE_CITIES",
payload: {
paginateCities,
},
});
});
};
};
export const getCitiesWithoutCoords = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
cities (sortBy: [{ direction: ASC, field: "name" }]) {
id
name
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const cities = response.data.data.cities;
dispatch({
type: "GET_CITIES_WITHOUT_COORDS",
payload: {
cities,
},
});
});
};
};

View File

@@ -0,0 +1,54 @@
import ApplicationService from "../../../services/ApplicationService";
export const getCity = (cityId) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
city(id: "${cityId}") {
id
name
coordinates
isDeleted
defaultCity
districts {
id
name
coordinates
city{
id
name
}
mainDataTables {
id
year
totalEmission
}
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const city = response.data.data.city;
dispatch({
type: "GET_CITY",
payload: {
city,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};

View File

@@ -0,0 +1,37 @@
import ApplicationService from "../../../services/ApplicationService";
export const getCountries = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
countries {
id
countryCode
name
isDeleted
defaultCountry
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const countries = response.data.data.countries;
dispatch({
type: "GET_COUNTRIES",
payload: {
countries,
},
});
});
};
};

View File

@@ -0,0 +1,424 @@
import ApplicationService from "../../../services/ApplicationService";
export const getDataCenters = () => {
return async (dispatch) => {
dispatch({
type: "GET_DATA_CENTERS_LOADING",
});
// Get access token
const accessToken = localStorage.getItem("accessToken");
if (!accessToken) {
dispatch({
type: "GET_DATA_CENTERS_ERROR",
payload: {
error: "No access token found. Please log in again.",
},
});
return;
}
ApplicationService.http()
.post(
"/graphql",
{
query: `
query GetDataCenters {
dataCenters(sortBy: [{ direction: DESC, field: "number" }]) {
id
dataCenter
externalId
ayposURL
number
address
latitude
longitude
area {
tag
cityNames
districtNames
}
projects {
id
name
physicalMachines {
id
name
vms {
active {
id
status
name
power
config {
id
cpu
ram
disk
}
}
}
}
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + accessToken,
"Content-Type": "application/json",
},
}
)
.then((response) => {
// Debug logging
console.log("GraphQL Response:", {
status: response.status,
data: response.data,
errors: response.data?.errors
});
// Check for GraphQL errors
if (response.data?.errors) {
throw new Error(response.data.errors[0].message);
}
// Validate response structure
if (!response.data?.data?.dataCenters) {
throw new Error("Invalid response structure: dataCenters not found");
}
const dataCenters = response.data.data.dataCenters;
// Validate dataCenters is an array
if (!Array.isArray(dataCenters)) {
throw new Error("Invalid response: dataCenters is not an array");
}
dispatch({
type: "GET_DATA_CENTERS_SUCCESS",
payload: {
dataCenters,
},
});
})
.catch((error) => {
// Enhanced error logging
console.error("Error fetching data centers:", {
message: error.message,
response: error.response?.data,
status: error.response?.status,
stack: error.stack
});
// Check for specific error types
let errorMessage = "Failed to fetch data centers";
if (error.response?.status === 401) {
errorMessage = "Unauthorized. Please log in again.";
} else if (error.response?.status === 403) {
errorMessage = "You don't have permission to view data centers.";
} else if (error.message) {
errorMessage = error.message;
}
dispatch({
type: "GET_DATA_CENTERS_ERROR",
payload: {
error: errorMessage,
},
});
});
};
};
export const createDataCenter = (dataCenterData) => {
return async (dispatch) => {
dispatch({
type: "CREATE_DATA_CENTER_LOADING",
});
try {
const response = await ApplicationService.http().post(
"/graphql",
{
query: `
mutation CreateDataCenter($input: DataCenterInput!) {
createDataCenter(input: $input) {
id
dataCenter
externalId
ayposURL
number
address
latitude
longitude
area {
tag
cityNames
districtNames
}
}
}
`,
variables: {
input: {
dataCenter: dataCenterData.name,
externalId: parseInt(dataCenterData.externalId),
ayposURL: dataCenterData.ayposURL || "",
number: parseInt(dataCenterData.number) || 1,
areaId: dataCenterData.areaId,
address: dataCenterData.address || "",
latitude: dataCenterData.latitude ? parseFloat(dataCenterData.latitude) : null,
longitude: dataCenterData.longitude ? parseFloat(dataCenterData.longitude) : null,
city: dataCenterData.city
}
}
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
// Debug logging
console.log("Create Response:", {
status: response.status,
data: response.data,
errors: response.data?.errors
});
if (response.data?.errors) {
throw new Error(response.data.errors[0].message);
}
if (!response.data?.data?.createDataCenter) {
throw new Error("Invalid response: createDataCenter data not found");
}
dispatch({
type: "CREATE_DATA_CENTER_SUCCESS",
payload: response.data.data.createDataCenter,
});
return response.data.data.createDataCenter;
} catch (error) {
console.error("Error creating data center:", error);
dispatch({
type: "CREATE_DATA_CENTER_ERROR",
payload: {
error: error.message || "Failed to create data center",
},
});
throw error;
}
};
};
export const updateDataCenter = (id, dataCenterData) => {
return async (dispatch) => {
dispatch({
type: "UPDATE_DATA_CENTER_LOADING",
});
try {
const response = await ApplicationService.http().post(
"/graphql",
{
query: `
mutation UpdateDataCenter($id: ID!, $input: DataCenterInput!) {
updateDataCenter(id: $id, input: $input) {
id
dataCenter
externalId
ayposURL
number
address
latitude
longitude
area {
tag
cityNames
districtNames
}
}
}
`,
variables: {
id: id,
input: {
dataCenter: dataCenterData.name,
externalId: parseInt(dataCenterData.externalId),
ayposURL: dataCenterData.ayposURL || "",
number: parseInt(dataCenterData.number) || 1,
areaId: dataCenterData.areaId,
address: dataCenterData.address || "",
latitude: dataCenterData.latitude ? parseFloat(dataCenterData.latitude) : null,
longitude: dataCenterData.longitude ? parseFloat(dataCenterData.longitude) : null,
city: dataCenterData.city
}
}
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
if (response.data?.errors) {
throw new Error(response.data.errors[0].message);
}
dispatch({
type: "UPDATE_DATA_CENTER_SUCCESS",
payload: response.data.data.updateDataCenter
});
return response.data.data.updateDataCenter;
} catch (error) {
console.error("Error updating data center:", error);
dispatch({
type: "UPDATE_DATA_CENTER_ERROR",
payload: {
error: error.message || "Failed to update data center",
},
});
throw error;
}
};
};
export const deleteDataCenter = (id) => {
return async (dispatch) => {
dispatch({
type: "DELETE_DATA_CENTER_LOADING",
});
try {
const response = await ApplicationService.http().post(
"/graphql",
{
query: `
mutation DeleteDataCenter($id: ID!) {
deleteDataCenter(id: $id)
}
`,
variables: {
id: id
}
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
if (response.data?.errors) {
throw new Error(response.data.errors[0].message);
}
dispatch({
type: "DELETE_DATA_CENTER_SUCCESS",
payload: id
});
return true;
} catch (error) {
console.error("Error deleting data center:", error);
dispatch({
type: "DELETE_DATA_CENTER_ERROR",
payload: {
error: error.message || "Failed to delete data center",
},
});
throw error;
}
};
};
export const getDataCenterVMs = (dataCenterId) => {
return new Promise(async (resolve, reject) => {
// Don't make the request if dataCenterId is undefined, null, or empty
if (!dataCenterId || dataCenterId === "undefined") {
console.log('getDataCenterVMs: No dataCenterId provided');
resolve([]);
return;
}
try {
console.log('getDataCenterVMs: Fetching VMs for data center:', dataCenterId);
const response = await ApplicationService.http()
.post(
"/graphql",
{
query: `
{
dataCenter(id: "${dataCenterId}") {
id
dataCenter
projects {
id
name
physicalMachines {
id
name
vms {
active {
id
name
status
power
}
inactive {
id
name
status
power
}
}
}
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
const dataCenter = response?.data?.data?.dataCenter;
console.log('getDataCenterVMs: Data center response:', dataCenter);
let allVMs = [];
if (dataCenter && dataCenter.projects) {
dataCenter.projects.forEach(project => {
if (project.physicalMachines) {
project.physicalMachines.forEach(pm => {
if (pm.vms) {
if (pm.vms.active) {
allVMs = allVMs.concat(pm.vms.active);
}
if (pm.vms.inactive) {
allVMs = allVMs.concat(pm.vms.inactive);
}
}
});
}
});
}
console.log('getDataCenterVMs: Found VMs:', allVMs);
resolve(allVMs);
} catch (error) {
console.error("Error fetching VMs by data center:", error);
resolve([]);
}
});
};

View File

@@ -0,0 +1,338 @@
import ApplicationService from "../../../services/ApplicationService";
export const getSectors = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
sectors {
id
tag
description
deleted
sectorNo
subSectors {
id
tag
description
deleted
subSectorNo
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const sectors = response.data.data.sectors;
dispatch({
type: "GET_SECTORS",
payload: {
sectors,
},
});
});
};
};
export const getSectorById = (id) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
sector(id: "${id}") {
id
tag
description
deleted
sectorNo
subSectors {
id
tag
description
deleted
subSectorNo
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const sector = response.data.data.sector;
dispatch({
type: "GET_SECTOR_BY_ID",
payload: {
sector,
},
});
});
};
};
export const getSubSectors = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
subSectors{
id
tag
description
deleted
sector {
id
tag
description
deleted
sectorNo
}
subSectorNo
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const subSectors = response.data.data.subSectors;
dispatch({
type: "GET_SUBSECTORS",
payload: {
subSectors,
},
});
});
};
};
export const getSubSectorById = (id) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
subSector(id: "${id}"){
id
tag
description
deleted
activitySubUnits {
id
tag
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const subSector = response.data.data.subSector;
dispatch({
type: "GET_SUBSECTOR_BY_ID",
payload: {
subSector: subSector || {},
},
});
});
};
};
export const getActivitySubUnits = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
activitySubUnits{
id
tag
description
deleted
subSector {
id
tag
description
deleted
sector{
id
tag
description
}
subSectorNo
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const activitySubUnits = response.data.data.activitySubUnits;
dispatch({
type: "GET_ACTIVITY_SUBUNITS",
payload: {
activitySubUnits,
},
});
});
};
};
export const getConsuptionUnits = ({ id, sector }) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query:
sector != "Atık"
? `
{
emissionSource(id: "${id}") {
emissionSourceConvertUnits {
unit {
id
tag
description
}
}
}
}
`
: `
{
consuptionUnits {
id
tag
description
deleted
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const consuptionUnits =
sector != "Atık"
? response.data.data.emissionSource?.emissionSourceConvertUnits
: response.data.data.consuptionUnits;
dispatch({
type: "GET_CONSUPTION_UNITS",
payload: {
consuptionUnits,
},
});
});
};
};
export const getGpcReferences = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
gpcReferences {
id
referenceNumber
description
deleted
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const gpcReferences = response.data.data.gpcReferences;
dispatch({
type: "GET_GPC_REFERENCES",
payload: {
gpcReferences,
},
});
});
};
};
export const getMcfTypes = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
mcfTypes {
id
typeName
value
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const mcfTypes = response.data.data.mcfTypes;
dispatch({
type: "GET_MCF_TYPES",
payload: {
mcfTypes,
},
});
});
};
};

View File

@@ -0,0 +1,62 @@
import ApplicationService from "../../../services/ApplicationService";
export const getDistrict = (districtId) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
district(id: "${districtId}") {
id
name
coordinates
isDeleted
defaultDistrict
neighborhoods {
id
name
minLong
maxLong
minLat
maxLat
mainDataTables {
id
year
totalEmission
}
district{
id
name
city{
id
name
}
}
}
city{
id
name
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const district = response.data.data.district;
dispatch({
type: "GET_DISTRICT",
payload: {
district,
},
});
});
};
};

View File

@@ -0,0 +1,55 @@
import ApplicationService from "../../../services/ApplicationService";
export const getDistricts = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
paginateDistricts(
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
data.rowsPerPage
} }
sortBy: [{ direction: ASC, field: "cityName" }]
) {
pageInfo {
totalElements
totalPages
numberOfElements
pageNumber
pageSize
}
content {
id
name
city{
id
name
country{
id
name
}
}
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const districts = response.data.data.paginateDistricts;
dispatch({
type: "GET_DISTRICTS",
payload: {
districts,
},
});
});
};
};

View File

@@ -0,0 +1,393 @@
import ApplicationService from "../../../services/ApplicationService";
export const getAllEmissionSources = (subSectorId) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
emissionSources(criteria: {subSector:"${subSectorId}"}) {
id
tag
convertUnitCheck
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const emissionSources = response.data.data.emissionSources?.filter(
(emissionSource) => emissionSource?.deleted != true
);
dispatch({
type: "GET_EMISSION_SOURCES",
payload: {
emissionSources,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const getEmissionSourcesWithPaginate = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
paginateEmissionSources(
pagination: {page: ${data.currentPage - 1}, rowsPerPage: ${
data.rowsPerPage
} }
criteria: {deleted: ${data.showDeletedEmissionSource}, sector:"${
data?.selectedSectorFilter
}"}
sortBy: [{ direction: ASC, field: "tag" }]
) {
pageInfo {
totalElements
totalPages
numberOfElements
pageNumber
pageSize
}
content {
id
tag
description
isDeleted
co2
ch4
n2o
emissionScope
subSector{
id
tag
description
deleted
subSectorNo
sector{
id
tag
description
}
}
emissionSourceConvertUnits {
value
unit{
id
tag
description
}
}
wasteEmissionSourceSupplement {
dryWeightCH4
wetWeightCH4
dryWeightN2O
wetWeightN2O
dampWeightCH4
}
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const emissionSourcesWithPaginate =
response.data.data.paginateEmissionSources;
dispatch({
type: "GET_EMISSION_SOURCES_WITH_PAGINATE",
payload: {
emissionSourcesWithPaginate,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const addEmissionSource = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
mutation {
createEmissionSource(
input: {
tag: "${data.tag}"
description: "${data.description}"
isDeleted: true
co2: "${data.co2}"
ch4: "${data.ch4}"
n2o: "${data.n2o}"
subSector: "${data.subSector}"
emissionScope:"${data.emissionScope}"
emissionSourceConvertUnitInputs: ${data.emissionSourceConvertUnits}
}
) {
id
tag
description
isDeleted
co2
ch4
n2o
emissionScope
subSector{
id
tag
description
deleted
sector{
id
tag
description
}
subSectorNo
}
emissionSourceConvertUnits {
value
unit{
id
tag
}
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "ADD_EMISSION_SOURCE",
payload: {
emissionSource: response.data.data.createEmissionSource,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const updateEmissionSource = (data) => async (dispatch) => {
try {
const response = await ApplicationService.http().post(
"/graphql",
{
query: `
mutation {
updateEmissionSource(id: "${data.id}",
input: {
tag: "${data.tag}"
description: "${data.description}"
isDeleted: true
co2: "${data.co2}"
ch4: "${data.ch4}"
n2o: "${data.n2o}"
subSector: "${data.subSector}"
emissionScope:"${data.emissionScope}"
emissionSourceConvertUnitInputs: ${data.emissionSourceConvertUnits}
}
) {
id
tag
description
isDeleted
co2
ch4
n2o
emissionScope
subSector{
id
tag
description
deleted
sector{
id
tag
description
}
subSectorNo
}
emissionSourceConvertUnits {
value
unit{
id
tag
}
}
wasteEmissionSourceSupplement {
dryWeightCH4
wetWeightCH4
dryWeightN2O
wetWeightN2O
dampWeightCH4
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
if (response.data.errors) {
const errorMessage = response.data.errors[0].extensions.ErrorCode;
throw errorMessage;
} else {
dispatch({
type: "UPDATE_EMISSION_SOURCE",
payload: {
emissionSource: response.data.data.updateEmissionSource,
},
});
}
} catch (error) {
console.log("Network error:", error);
throw error;
}
};
export const updateEmissionSourceOfWaste = (data) => async (dispatch) => {
try {
const response = await ApplicationService.http().post(
"/graphql",
{
query: `
mutation {
updateEmissionSource(id: "${data.id}",
input: {
tag: "${data.tag}"
subSector: "${data.subSector}"
dampWeightCh4: "${data.dampWeightCH4}"
dryWeightCh4: "${data.dryWeightCH4}"
dryWeightN2o: "${data.dryWeightN2O}"
wetWeightCh4: "${data.wetWeightCH4}"
wetWeightN2o: "${data.wetWeightN2O}"
}
) {
id
tag
description
isDeleted
co2
ch4
n2o
emissionScope
subSector{
id
tag
description
deleted
sector{
id
tag
description
}
subSectorNo
}
emissionSourceConvertUnits {
value
unit{
id
tag
}
}
wasteEmissionSourceSupplement {
dryWeightCH4
wetWeightCH4
dryWeightN2O
wetWeightN2O
dampWeightCH4
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
if (response.data.errors) {
const errorMessage = response.data.errors[0].extensions.ErrorCode;
throw errorMessage;
} else {
dispatch({
type: "UPDATE_EMISSION_SOURCE_OF_WASTE",
payload: {
emissionSource: response.data.data.updateEmissionSource,
},
});
}
} catch (error) {
console.log("Network error:", error);
throw error;
}
};
export const deleteEmissionSource = (id) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
mutation {
deleteEmissionSource(id: "${id}")
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then(() => {
dispatch({
type: "DELETE_EMISSION_SOURCE",
payload: {
id: id,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};

View File

@@ -0,0 +1,11 @@
// ** Handles Layout Content Width (full / boxed)
export const handleContentWidth = value => dispatch => dispatch({ type: 'HANDLE_CONTENT_WIDTH', value })
// ** Handles Menu Collapsed State (Bool)
export const handleMenuCollapsed = value => dispatch => dispatch({ type: 'HANDLE_MENU_COLLAPSED', value })
// ** Handles Menu Hidden State (Bool)
export const handleMenuHidden = value => dispatch => dispatch({ type: 'HANDLE_MENU_HIDDEN', value })
// ** Handles RTL (Bool)
export const handleRTL = value => dispatch => dispatch({ type: 'HANDLE_RTL', value })

View File

@@ -0,0 +1,105 @@
import ApplicationService from "../../../services/ApplicationService";
export const getMailSettings = () => {
return async (dispatch) => {
dispatch({ type: "GET_MAIL_SETTINGS_PENDING" });
try {
const response = await ApplicationService.http().post(
"/graphql",
{
query: `
query GetMainMailInfo {
mainMailInfo {
id
hostName
smtpPort
emailAddress
mainMail
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
dispatch({
type: "GET_MAIL_SETTINGS_FULFILLED",
payload: response.data.data.mainMailInfo,
});
} catch (error) {
dispatch({
type: "GET_MAIL_SETTINGS_REJECTED",
payload: error.response?.data || error.message,
});
}
};
};
export const updateMailSettings = (mailData) => {
return async (dispatch) => {
dispatch({ type: "UPDATE_MAIL_SETTINGS_PENDING" });
try {
const { id, hostName, smtpPort, emailAddress, emailPassword, mainMail } =
mailData;
let variables = { id, hostName, smtpPort, emailAddress, mainMail };
if (emailPassword) {
variables.emailPassword = emailPassword;
}
const response = await ApplicationService.http().post(
"/graphql",
{
query: `
mutation UpdateMailInfo($id: ID!, $hostName: String, $smtpPort: Int, $emailAddress: String, $emailPassword: String, $mainMail: Boolean) {
updateMailInfo(
id: $id,
hostName: $hostName,
smtpPort: $smtpPort,
emailAddress: $emailAddress,
emailPassword: $emailPassword,
mainMail: $mainMail
) {
id
hostName
smtpPort
emailAddress
mainMail
}
}
`,
variables,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
dispatch({
type: "UPDATE_MAIL_SETTINGS_FULFILLED",
payload: response.data.data.updateMailInfo,
});
} catch (error) {
dispatch({
type: "UPDATE_MAIL_SETTINGS_REJECTED",
payload: error.response?.data || error.message,
});
}
};
};
export const clearMailError = () => ({
type: "CLEAR_MAIL_ERROR",
});
export const clearMailSuccess = () => ({
type: "CLEAR_MAIL_SUCCESS",
});

View File

@@ -0,0 +1,807 @@
import ApplicationService from "../../../services/ApplicationService";
export const getVMEmissionSummary = () => {
return async (dispatch) => {
try {
const response = await ApplicationService.http()
.post(
"/graphql",
{
query: `
{
vmEmissionSummary {
vmId
vmName
vmPower
vmStatus
totalEmission
createdDate
physicalMachine
project
dataCenter
co2
ch4
n2o
reportGeneratedTime
}
}
`
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
if (response.data.errors) {
console.error("GraphQL Errors:", response.data.errors);
throw new Error(response.data.errors[0]?.message || "GraphQL Error");
}
const vmEmissionSummary = response.data.data.vmEmissionSummary;
dispatch({
type: "GET_VM_EMISSION_SUMMARY",
payload: {
vmEmissionSummary,
},
});
} catch (error) {
console.error("API Error:", error);
throw error;
}
};
};
export const getMainDataTables = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
mainDataTables(
criteria:{
year:"${data?.filterOptions?.year?.value}"
deleted:false,
city:"${data?.filterOptions.city}",
district:"${data?.filterOptions.district}",
neighborhood:"${data?.filterOptions.neighborhood}",
}
) {
year
sector {
id
tag
}
subSector{
id
tag
}
activitySubUnit{
id
tag
}
totalEmission
emissionScope{
tag
}
emissionSource{
id
tag
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const mainDataTables = response.data.data.mainDataTables;
dispatch({
type: "GET_MAIN_TABLES",
payload: {
mainDataTables,
},
});
});
};
};
export const getMainDataTablesWithPaginate = (data) => {
return async (dispatch) => {
try {
const response = await ApplicationService.http()
.post(
"/graphql",
{
query: `
{
paginateMainDataTables(
pagination: { page: 0, rowsPerPage: 100 }
criteria: { deleted: false }
sortBy: [{ field: "createdDate", direction: DESC }]
) {
content {
id
sector {
id
tag
}
subSector {
id
tag
}
co2
ch4
n2o
totalEmission
createdDate
}
pageInfo {
totalElements
totalPages
pageNumber
pageSize
}
}
}
`
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
if (response.data.errors) {
console.error("GraphQL Errors:", response.data.errors);
throw new Error(response.data.errors[0]?.message || "GraphQL Error");
}
const mainDataTablesWithPaginate = response.data.data.paginateMainDataTables;
// Log the response for debugging
console.log("API Response:", response.data);
dispatch({
type: "GET_MAIN_TABLES_WITH_PAGINATE",
payload: {
mainDataTablesWithPaginate,
},
});
} catch (error) {
console.error("API Error:", error);
throw error;
}
};
};
export const addDataInput = (data) => async (dispatch) => {
try {
const dataToJSON = JSON.stringify(data);
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
const response = await ApplicationService.http().post(
"/graphql",
{
query: `
mutation {
createMainDataTable(input: ${deleteQuotesFromKey}) {
id
createdDate
co2
ch4
n2o
totalEmission
deleted
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
if (response.data.errors) {
const errorMessage = response.data.errors[0].extensions.ErrorCode;
throw errorMessage;
} else {
dispatch({
type: "ADD_DATA_INPUT",
payload: {
dataInput: response.data.data.createMainDataTable,
},
});
}
} catch (error) {
console.log("Network error:", error);
throw error;
}
};
export const createSolidWasteMainDataTable = (data) => async (dispatch) => {
try {
const dataToJSON = JSON.stringify(data);
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
const response = await ApplicationService.http().post(
"/graphql",
{
query: `
mutation {
createSolidWasteMainDataTable(input: ${deleteQuotesFromKey}) {
id
createdDate
co2
ch4
n2o
totalEmission
deleted
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
if (response.data.errors) {
const errorMessage = response.data.errors[0].extensions.ErrorCode;
throw errorMessage;
} else {
dispatch({
type: "ADD_SOLID_WASTE",
payload: {
dataInput: response.data.data.createSolidWasteMainDataTable,
},
});
}
} catch (error) {
console.log("Network error:", error);
throw error;
}
};
export const createWasteMainDataTable = (data) => async (dispatch) => {
try {
const dataToJSON = JSON.stringify(data);
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
const response = await ApplicationService.http().post(
"/graphql",
{
query: `
mutation {
createWasteMainDataTable(input: ${deleteQuotesFromKey}) {
id
createdDate
co2
ch4
n2o
totalEmission
deleted
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
if (response.data.errors) {
const errorMessage = response.data.errors[0].extensions.ErrorCode;
throw errorMessage;
} else {
dispatch({
type: "ADD_WASTE",
payload: {
dataInput: response.data.data.createWasteMainDataTable,
},
});
}
} catch (error) {
console.log("Network error:", error);
throw error;
}
};
export const updateDataInput = (data) => async (dispatch) => {
try {
let deleteIdFromData = { ...data };
delete deleteIdFromData.id;
const dataToJSON = JSON.stringify(deleteIdFromData);
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
const response = await ApplicationService.http().post(
"/graphql",
{
query: `
mutation {
updateMainDataTable(id: "${data.id}",input: ${deleteQuotesFromKey}) {
id
createdDate
year
month
city {
id
name
}
district {
id
name
city {
id
name
}
}
neighborhood {
id
name
district {
id
name
city {
id
name
}
}
}
sector {
id
tag
}
subSector {
id
tag
}
emissionSource {
id
tag
}
activitySubUnit {
id
tag
}
consuptionUnit {
id
tag
description
}
emissionScope {
id
tag
}
gpcReference
solidWasteSupplement{
domestic
frec
garden
industrial
mcfType{
id
typeName
value
}
methaneCaptureRate
paper
textile
tree
}
consuptionAmount
co2
ch4
n2o
totalEmission
deleted
scopeCheck
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
if (response.data.errors) {
const errorMessage = response.data.errors[0].extensions.ErrorCode;
throw errorMessage;
} else {
dispatch({
type: "UPDATE_DATA_INPUT",
payload: {
dataInput: response.data.data.updateMainDataTable,
},
});
}
} catch (error) {
console.log("Network error:", error);
throw error;
}
};
export const updateSolidWasteMainDataTable = (data) => async (dispatch) => {
try {
let deleteIdFromData = { ...data };
delete deleteIdFromData.id;
const dataToJSON = JSON.stringify(deleteIdFromData);
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
const response = await ApplicationService.http().post(
"/graphql",
{
query: `
mutation {
updateSolidWasteMainDataTable(id: "${data.id}",input: ${deleteQuotesFromKey}) {
id
createdDate
year
month
city {
id
name
}
district {
id
name
city {
id
name
}
}
neighborhood {
id
name
district {
id
name
city {
id
name
}
}
}
sector {
id
tag
}
subSector {
id
tag
}
emissionSource {
id
tag
}
activitySubUnit {
id
tag
}
consuptionUnit {
id
tag
description
}
emissionScope {
id
tag
}
gpcReference
solidWasteSupplement{
domestic
frec
garden
industrial
mcfType{
id
typeName
value
}
methaneCaptureRate
paper
textile
tree
}
consuptionAmount
co2
ch4
n2o
totalEmission
deleted
scopeCheck
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
if (response.data.errors) {
const errorMessage = response.data.errors[0].extensions.ErrorCode;
throw errorMessage;
} else {
dispatch({
type: "UPDATE_SOLID_WASTE",
payload: {
dataInput: response.data.data.updateSolidWasteMainDataTable,
},
});
}
} catch (error) {
//console.log("Network error:", error);
throw error;
}
};
export const updateWasteMainDataTable = (data) => async (dispatch) => {
try {
let deleteIdFromData = { ...data };
delete deleteIdFromData.id;
const dataToJSON = JSON.stringify(deleteIdFromData);
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
const response = await ApplicationService.http().post(
"/graphql",
{
query: `
mutation {
updateWasteMainDataTable(id: "${data.id}",input: ${deleteQuotesFromKey}) {
id
createdDate
year
month
city {
id
name
}
district {
id
name
city {
id
name
}
}
neighborhood {
id
name
district {
id
name
city {
id
name
}
}
}
sector {
id
tag
}
subSector {
id
tag
}
emissionSource {
id
tag
}
activitySubUnit {
id
tag
}
consuptionUnit {
id
tag
description
}
emissionScope {
id
tag
}
gpcReference
weightType
personCount
proteinAmount
burnOrOpenBurn
consuptionAmount
co2
ch4
n2o
totalEmission
deleted
scopeCheck
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
if (response.data.errors) {
const errorMessage = response.data.errors[0].extensions.ErrorCode;
throw errorMessage;
} else {
dispatch({
type: "UPDATE_WASTE",
payload: {
dataInput: response.data.data.updateWasteMainDataTable,
},
});
}
} catch (error) {
//console.log("Network error:", error);
throw error;
}
};
export const deleteDataInput = (dataId) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `mutation {
deleteMainDataTable(id:"${dataId}")
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then(() => {
dispatch({
type: "DELETE_DATA_INPUT",
payload: {
id: dataId,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const getMainDataTablesByVMs = (data) => {
return async (dispatch) => {
const { filterOptions } = data;
try {
const response = await ApplicationService.http()
.post(
"/graphql",
{
query: `
{
mainDataTables(
criteria: {
year: "${filterOptions?.year?.value}"
deleted: false
}
) {
year
sector { id tag }
subSector{ id tag }
activitySubUnit{ id tag }
totalEmission
emissionScope{ tag }
emissionSource{ id tag }
vm { id name status power }
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
const allMainDataTables = response.data.data.mainDataTables || [];
dispatch({
type: "GET_MAIN_TABLES",
payload: {
mainDataTables: allMainDataTables,
},
});
} catch (error) {
console.error("Error fetching main data tables:", error);
dispatch({
type: "GET_MAIN_TABLES",
payload: {
mainDataTables: [],
},
});
}
};
};
export const testMainDataTables = () => {
return async (dispatch) => {
try {
console.log('testMainDataTables: Testing basic mainDataTables query');
const response = await ApplicationService.http()
.post(
"/graphql",
{
query: `
{
mainDataTables(
criteria: {
deleted: false
}
) {
id
year
totalEmission
vm {
id
name
status
power
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
console.log('testMainDataTables: Response:', response.data);
if (response.data.errors) {
console.error('testMainDataTables: GraphQL Errors:', response.data.errors);
}
const allData = response.data.data.mainDataTables || [];
console.log('testMainDataTables: All mainDataTables:', allData);
console.log('testMainDataTables: Count:', allData.length);
// Check which records have VM data
const recordsWithVM = allData.filter(record => record.vm);
console.log('testMainDataTables: Records with VM:', recordsWithVM);
console.log('testMainDataTables: Records with VM count:', recordsWithVM.length);
dispatch({
type: "GET_MAIN_TABLES",
payload: {
mainDataTables: allData,
},
});
} catch (error) {
console.error("testMainDataTables: Error:", error);
}
};
};

View File

@@ -0,0 +1,209 @@
import ApplicationService from "../../../services/ApplicationService";
export const getNeighborhoods = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
paginateNeighborhoods(
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
data.rowsPerPage
} }
sortBy: [{ direction: ASC, field: "districtCityName" }]
) {
pageInfo {
totalElements
totalPages
numberOfElements
pageNumber
pageSize
}
content {
id
name
district {
id
name
city {
id
name
}
}
minLong
maxLong
minLat
maxLat
isDeleted
defaultNeighborhood
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const neighborhoods = response.data.data.paginateNeighborhoods;
dispatch({
type: "GET_NEIGHBORHOODS",
payload: {
neighborhoods,
},
});
});
};
};
export const addNeighborhood = (neighborhood) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
mutation {
createNeighborhood(
input: {
name: "${neighborhood.name}",
district:"${neighborhood.district}",
minLat:${Number(neighborhood.lat)},
minLong:${Number(neighborhood.long)},
maxLat:${Number(neighborhood.lat)},
maxLong:${Number(neighborhood.long)}
}
) {
id
name
district {
id
name
city{
id
name
}
}
minLong
maxLong
minLat
maxLat
isDeleted
defaultNeighborhood
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "ADD_NEIGHBORHOOD",
payload: {
neighborhoods: response.data.data.createNeighborhood,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const updateNeighborhood = (neighborhood) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
mutation {
updateNeighborhood(id:"${neighborhood.id}",
input: {
name: "${neighborhood.name}",
district:"${neighborhood.district}",
minLat:${neighborhood.lat},
minLong:${neighborhood.long},
maxLat:${neighborhood.lat},
maxLong:${neighborhood.long}
}
) {
id
name
district {
id
name
city{
id
name
}
}
minLong
maxLong
minLat
maxLat
isDeleted
defaultNeighborhood
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "UPDATE_NEIGHBORHOOD",
payload: {
neighborhoods: response.data.data.updateNeighborhood,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const deleteNeighborhood = (id) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `mutation {
deleteNeighborhood(id:"${id}")
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then(() => {
dispatch({
type: "DELETE_NEIGHBORHOOD",
payload: {
id: id,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};

View File

@@ -0,0 +1,162 @@
import ApplicationService from "../../../services/ApplicationService";
export const getQuickNotifications = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
mutation {
getQuickNotifications {
id
createdDateTime
title
message
read
notificationType
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const getQuickNotifications = response.data.data.getQuickNotifications;
dispatch({
type: "GET_QUICKNOTIFICATIONS",
payload: {
getQuickNotifications,
},
});
});
};
};
export const setNotificationRead = (id) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
mutation {
setNotificationRead(id: "${id}") {
id
createdDateTime
title
message
read
notificationType
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const setNotificationRead = response.data.data.setNotificationRead;
dispatch({
type: "GET_SETNOTIFICATIONREAD",
payload: {
setNotificationRead,
},
});
});
};
};
export const getAllNotifications = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
mutation {
getAllNotifications(
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
data.rowsPerPage
} }
sortBy: [{ direction: DESC, field: "createdDateTime" }]
) {
pageInfo {
totalElements
totalPages
numberOfElements
pageNumber
pageSize
}
content {
id
createdDateTime
title
message
read
notificationType
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const getAllNotifications = response.data.data.getAllNotifications;
dispatch({
type: "GET_ALLNOTIFICATION",
payload: {
getAllNotifications,
},
});
});
};
};
export const notificationRemove = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
mutation {
notificationRemove(id: "${data.selectedId}")
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const notificationRemove = response.data.data.notificationRemove;
dispatch({
type: "GET_NOTIFICATIONREMOVE",
payload: {
notificationRemove,
},
});
if (notificationRemove === true) {
let currentPage = data.currentPage;
let rowsPerPage = data.rowsPerPage;
dispatch(getAllNotifications({ currentPage, rowsPerPage }));
}
});
};
};

View File

@@ -0,0 +1,360 @@
import ApplicationService from "../../../services/ApplicationService";
export const getOrganisations = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
organizations {
id
tag
description
isDefault
deleted
areas{
id
tag
}
parents {
parent{
id
tag
deleted
}
}
children {
child{
id
tag
deleted
}
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const organisations = response.data.data.organizations?.filter(
(organization) => organization?.deleted != true
);
dispatch({
type: "GET_ORGANISATIONS",
payload: {
organisations,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const getOrganizationsWithPaginate = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
paginateOrganizations(
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
data.rowsPerPage
} }
criteria:{ deleted:${data.showDeletedOrganizations} }
sortBy: [{ direction: ASC, field: "tag" }]
) {
pageInfo {
totalElements
totalPages
numberOfElements
pageNumber
pageSize
}
content {
id
tag
description
isDefault
deleted
areas{
id
tag
}
parents {
parent{
id
tag
deleted
}
}
children {
child{
id
tag
deleted
}
}
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const organizationsWithPaginate =
response.data.data.paginateOrganizations;
dispatch({
type: "GET_ORGANIZATIONS_WITH_PAGINATE",
payload: {
organizationsWithPaginate,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const getOrganisationById = (organizationId) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `{
organization(id: "${organizationId}") {
id
tag
description
isDefault
deleted
areas{
id
tag
}
parents {
id
parent{
id
tag
deleted
}
}
children {
id
child{
id
tag
deleted
}
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const organisation = response.data.data.organization;
dispatch({
type: "GET_ORGANISATION_BY_ID",
payload: {
organisation,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const addOrganization = (data) => {
const dataToJSON = JSON.stringify(data);
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
mutation {
createOrganization(input: ${deleteQuotesFromKey}) {
id
tag
description
isDefault
deleted
areas{
id
tag
}
parents {
parent{
id
tag
deleted
}
}
children {
child{
id
tag
deleted
}
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "ADD_ORGANIZATION",
payload: {
organisation: response.data.data.createOrganization,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const updateOrganization = (data) => {
let deleteIdFromData = { ...data };
delete deleteIdFromData.id;
const dataToJSON = JSON.stringify(deleteIdFromData);
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query:
`
mutation {
updateOrganization(id: "` +
data.id +
`", input: ${deleteQuotesFromKey}) {
id
tag
description
isDefault
deleted
areas{
id
tag
}
parents {
parent{
id
tag
deleted
}
}
children {
child{
id
tag
deleted
}
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const organisation = response.data.data.updateOrganization;
dispatch({
type: "UPDATE_ORGANIZATION",
payload: {
organisation: organisation,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const deleteOrganization = (id) => {
return async (dispatch) => {
return ApplicationService.http()
.post(
"/graphql",
{
query:
`
mutation {
deleteOrganization(id: "` +
id +
`")
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
// Check if there are errors in the response
if (response.data.errors) {
// Return the error message to be handled by the component
return { error: response.data.errors[0].message };
}
// If successful, dispatch the action and return success
dispatch({
type: "DELETE_ORGANIZATION",
payload: {
id: id,
},
});
return { success: true };
})
.catch((error) => {
console.log("error", error);
// Return a generic error message to be handled by the component
return { error: "An error occurred while deleting the organization" };
});
};
};

View File

@@ -0,0 +1,82 @@
import ApplicationService from "../../../services/ApplicationService";
export const getUserPermissions = () => {
const roleId = localStorage.getItem("roleId");
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
role(id: "${roleId}") {
permissions {
id
tag
description
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
//alfabetik sıralama
const sortPermissions = response.data.data.role?.permissions.sort(
function (a, b) {
return a.description.localeCompare(b.description);
}
);
const userpermissions = sortPermissions;
dispatch({
type: "GET_USERPERMISSIONS",
payload: {
userpermissions,
},
});
});
};
};
export const getAllPermissions = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
permissions {
id
tag
description
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const sortPermissions = response.data.data.permissions.sort(
function (a, b) {
return a.description.localeCompare(b.description);
}
);
dispatch({
type: "GET_PERMISSIONS",
payload: {
permissions: sortPermissions,
},
});
});
};
};

View File

@@ -0,0 +1,213 @@
import ApplicationService from "../../../services/ApplicationService";
export const getQuestions = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
questions {
id
tag
question
isDefault
isDeleted
createdAt
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const questions1 = response.data.data.questions;
const questions = questions1.filter(
(question) => question.isDeleted != true
);
dispatch({
type: "GET_QUESTİONS",
payload: {
questions,
},
});
});
};
};
export const getQuestionsWithPaginate = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
paginateQuestions(
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
data.rowsPerPage
} }
criteria:{deleted:false}
sortBy: [{ direction: ASC, field: "tag" }]
) {
pageInfo {
totalElements
totalPages
numberOfElements
pageNumber
pageSize
}
content {
id
tag
question
isDefault
isDeleted
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const questionsWithPaginate = response?.data?.data?.paginateQuestions;
dispatch({
type: "GET_QUESTİONS_WITH_PAGINATE",
payload: {
questionsWithPaginate,
},
});
});
};
};
export const addQuestion = (data) => {
const dataToJSON = JSON.stringify(data);
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
mutation {
createQuestion(
input: ${deleteQuotesFromKey} )
{
id
tag
question
isDefault
isDeleted
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "ADD_QUESTİON",
payload: {
questions: response.data.data.createQuestion,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const updateQuestion = (data) => {
let deleteIdFromData = { ...data };
delete deleteIdFromData.id;
const dataToJSON = JSON.stringify(deleteIdFromData);
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query:
`
mutation {
updateQuestion(id: "` +
data.id +
`", input: ${deleteQuotesFromKey}) {
id
tag
question
isDeleted
isDefault
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "UPDATE_QUESTİON",
payload: {
questions: response.data.data.updateQuestion,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const deleteQuestion = (id) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `mutation {
deleteQuestion(id:"${id}")
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then(() => {
dispatch({
type: "DELETE_QUESTİON",
payload: {
id: id,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};

View File

@@ -0,0 +1,229 @@
import ApplicationService from "../../../services/ApplicationService";
const roleTag = localStorage.getItem("roleTag");
export const getRoles = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
roles {
id
tag
permissions{
id
tag
description
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const roles =
roleTag === "SUPER_ADMIN"
? response.data.data.roles
: response.data.data.roles.filter(
(role) => role.tag !== "SUPER_ADMIN"
);
dispatch({
type: "GET_ROLES",
payload: {
roles,
},
});
});
};
};
export const getRolesWithPaginate = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
paginateRoles(
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
data.rowsPerPage
} }
sortBy: [{ direction: ASC, field: "tag" }]
) {
pageInfo {
totalElements
totalPages
numberOfElements
pageNumber
pageSize
}
content {
id
tag
permissions {
id
tag
description
}
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
let roles = {};
if (roleTag === "SUPER_ADMIN") {
roles = response.data.data.paginateRoles;
} else {
const filteredRoles =
response.data.data.paginateRoles?.content?.filter(
(role) => role.tag !== "SUPER_ADMIN"
);
roles = {
...response.data.data.paginateRoles,
content: filteredRoles,
};
}
dispatch({
type: "GET_ROLES_WITH_PAGINATE",
payload: {
roles,
},
});
});
};
};
export const addRoles = (role) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
mutation {
createRole(
input: {
tag: "${role.tag}",
permissions:[${role.permissions}]
}
) {
id
tag
permissions{
id
tag
description
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "ADD_ROLES",
payload: {
roles: response.data.data.createRole,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const updateRoles = (role) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
mutation {
updateRole(id:"${role.id}",
input: {
tag:"${role.tag}",
permissions:[${role.permissions}]
}
) {
id
tag
permissions {
id
tag
description
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "UPDATE_ROLES",
payload: {
roles: response.data.data.updateRole,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const deleteRoles = (roleId) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `mutation {
deleteRole(id:"${roleId}")
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then(() => {
dispatch({
type: "DELETE_ROLES",
payload: {
id: roleId,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};

View File

@@ -0,0 +1,509 @@
import ApplicationService from "../../../services/ApplicationService";
export const getSurvey = (surveyId) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
survey(id: "${surveyId}") {
id
tag
description
isDefault
isDeleted
createdAt
relationSurveyQuestions {
id
isDeleted
question{
id
tag
question
relationQuestionAnswers{
id
answer{
answer
}
}
}
orderNo
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const survey = response.data?.data?.survey;
//const survey = survey1.filter((survey) => survey.isDeleted != true);
dispatch({
type: "GET_SURVEY",
payload: {
survey,
},
});
});
};
};
export const getSurveysWithPaginate = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
paginateSurveys(
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
data.rowsPerPage
} }
criteria: {deleted:false}
sortBy: [{ direction: ASC, field: "id" }]
) {
pageInfo {
totalElements
totalPages
numberOfElements
pageNumber
pageSize
}
content {
id
tag
description
isDefault
isDeleted
createdAt
relationSurveyQuestions {
id
isDeleted
question {
id
question
relationQuestionAnswers {
answer {
id
answer
}
}
}
orderNo
}
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const surveysWithPaginate = response?.data?.data?.paginateSurveys;
dispatch({
type: "GET_SURVEYS_WITH_PAGINATE",
payload: {
surveysWithPaginate,
},
});
});
};
};
export const savedSurveys = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
savedSurveys(sortBy: [{ direction: ASC, field: "id" }]) {
questionValue
answerValue
isDeleted
isApproved
publishedSurvey {
id
participant_email
participant_id
isDeleted
isUsed
created_at
start_at
expire_at
survey{
id
tag
description
}
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const savedSurveys = response?.data?.data?.savedSurveys;
dispatch({
type: "SAVED_SURVEYS",
payload: {
savedSurveys,
},
});
});
};
};
export const savedSurveysFromSurveys = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
surveys(criteria: { deleted: false }){
id
tag
description
createdAt
publishedSurveys {
id
participant_email
participant_id
created_at
start_at
expire_at
savedSurveys{
answerValue
questionValue
}
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const savedSurveysFromSurveys = response?.data?.data?.surveys;
dispatch({
type: "SAVED_SURVEYS_FROM_SURVEYS",
payload: {
savedSurveysFromSurveys,
},
});
});
};
};
export const addSurvey = (data) => {
const dataToJSON = JSON.stringify(data);
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
mutation {
addSurvey(
input: ${deleteQuotesFromKey}
) {
id
tag
description
isDefault
isDeleted
createdAt
relationSurveyQuestions {
id
isDeleted
question {
question
relationQuestionAnswers {
answer {
answer
}
}
}
orderNo
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "ADD_SURVEY",
payload: {
surveys: response.data.data.addSurvey,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const addQuestionToSurvey = (data) => {
let deleteIdFromData = { ...data };
delete deleteIdFromData.id;
const dataToJSON = JSON.stringify(deleteIdFromData);
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query:
`
mutation {
addQuestionToSurvey(surveyId: "` +
data.id +
`",
input: ${deleteQuotesFromKey}
) {
id
tag
description
isDefault
isDeleted
createdAt
relationSurveyQuestions {
id
isDeleted
question {
question
relationQuestionAnswers {
answer {
answer
}
}
}
orderNo
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "ADD_QUESTION_TO_SURVEY",
payload: {
surveys: response.data.data.addQuestionToSurvey,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const publishedSurvey = (publishedId) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
publishedSurvey(id: "${publishedId}") {
id
q_link
participant_email
participant_id
isDefault
isDeleted
isUsed
created_at
start_at
expire_at
survey {
id
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const publishedSurvey = response.data.data.publishedSurvey;
//const survey = survey1.filter((survey) => survey.isDeleted != true);
dispatch({
type: "PUBLİSHED_SURVEY",
payload: {
publishedSurvey,
},
});
});
};
};
/*
export const updateQuestion = (data) => {
let deleteIdFromData = { ...data };
delete deleteIdFromData.id;
const dataToJSON = JSON.stringify(deleteIdFromData);
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query:
`
mutation {
updateQuestion(id: "` +
data.id +
`", input: ${deleteQuotesFromKey}) {
id
tag
question
isDeleted
isDefault
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "UPDATE_QUESTİON",
payload: {
questions: response.data.data.updateQuestion,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
*/
export const deleteQuestionFromSurvey = ({ surveyId, deleteQuestionId }) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query:
`mutation {
deleteQuestionFromSurvey(surveyId: "` +
surveyId +
`",surveyQuestionRelationId: "` +
deleteQuestionId +
`"){
id
tag
description
isDefault
isDeleted
createdAt
relationSurveyQuestions {
id
isDeleted
question{
question
}
orderNo
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "DELETE_QUESTİON_FROM_SURVEY",
payload: {
data: response.data.data.deleteQuestionFromSurvey,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const deleteSurvey = (id) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `mutation {
deleteSurvey(id:"${id}")
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then(() => {
dispatch({
type: "DELETE_SURVEY",
payload: {
id: id,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};

View File

@@ -0,0 +1,37 @@
import ApplicationService from "../../../services/ApplicationService";
export const getSystemHistory = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
systemHistories (sortBy: [{ direction: ASC, field: "createdDateTime" }]){
id
createdDateTime
hash
logMessage
logType
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const systemHistories = response.data.data.systemHistories.reverse();
dispatch({
type: "GET_SYSTEMHISTORY",
payload: {
systemHistories,
},
});
});
};
};

View File

@@ -0,0 +1,27 @@
import ApplicationService from "../../../services/ApplicationService";
export const excelUpload = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: ``,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const excelUpload = response.data.data.excelUpload;
dispatch({
type: "EXCEL_UPLOAD",
payload: {
excelUpload,
},
});
});
};
};

View File

@@ -0,0 +1,138 @@
import ApplicationService from "../../../services/ApplicationService";
export const getUser = (userId) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
user(id: "${userId}") {
id
firstName
lastName
email
phoneNumber
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const user = response.data.data.user;
dispatch({
type: "GET_USER",
payload: {
user,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const updateUserInfo = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query:
`
mutation {
updateUser(id: "` +
data.id +
`", input: {firstName:"` +
data.firstName +
`",lastName:"` +
data.lastName +
`", email:"` +
data.email +
`",phoneNumber:"` +
data.phoneNumber +
`"}) {
id
firstName
lastName
email
phoneNumber
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const user = response.data.data.updateUser;
dispatch({
type: "UPDATE_USERINFO",
payload: {
data: response.data.data.user,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const updatePassword = (data) => async (dispatch) => {
try {
const response = await ApplicationService.http().post(
"/graphql",
{
query:
`
mutation {
updateUser(id: "` +
data.userId +
`", input: {password:"` +
data.newPassword +
`",oldPassword:"` +
data.oldPassword +
`"}) {
id
firstName
lastName
email
phoneNumber
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
);
if (response.data.errors) {
const errorMessage = response.data.errors[0].extensions.ErrorCode;
throw errorMessage;
} else {
dispatch({
type: "UPDATE_PASSWORD",
payload: {
data: response.data.data.updateUser,
},
});
}
} catch (error) {
console.log("Network Error", error);
throw error;
}
};

View File

@@ -0,0 +1,53 @@
import ApplicationService from "../../../services/ApplicationService";
export const getUserHistory = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
paginateUserHistories(
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
data.rowsPerPage
}
}
sortBy: [{ direction: DESC, field: "createdDateTime" }]
) {
pageInfo {
totalElements
totalPages
numberOfElements
pageNumber
pageSize
}
content {
id
createdDateTime
hash
logMessage
logType
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const userhistories = response.data.data.paginateUserHistories;
dispatch({
type: "GET_USERHISTORY",
payload: {
userhistories,
},
});
});
};
};

View File

@@ -0,0 +1,89 @@
import ApplicationService from "../../../services/ApplicationService";
export const getUserProfileSettings = () => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
mutation {
getUserProfileSettings {
id
user
infoMail
errorMail
infoNotification
errorNotification
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const getUserProfileSettings =
response.data.data.getUserProfileSettings;
dispatch({
type: "GET_USERPROFILESETTING",
payload: {
getUserProfileSettings,
},
});
})
.catch((error) => {
console.log("error -- responsee", error);
});
};
};
export const updateUserProfileSettings = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
mutation {
updateUserProfileSettings(
input: {
infoMail: ${data.infoMail}
errorMail: ${data.errorMail}
infoNotification: ${data.infoNotification}
errorNotification: ${data.errorNotification}
}
) {
id
user
infoMail
errorMail
infoNotification
errorNotification
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "UPDATE_USERPROFILESETTING",
payload: {
data: response.data.data.updateUserProfileSettings,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};

View File

@@ -0,0 +1,233 @@
import ApplicationService from "../../../services/ApplicationService";
export const getUsersHttp = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query: `
{
paginateUsers(
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
data.rowsPerPage
} }
criteria: {organizations:"${
data?.selectedOrganization?.value
? data?.selectedOrganization?.value
: data?.selectedOrganization
}",delete:${data.showDeletedUsers}}
sortBy: [{ direction: ASC, field: "firstName" }]
) {
pageInfo {
totalElements
totalPages
numberOfElements
pageNumber
pageSize
}
content {
id
firstName
lastName
email
phoneNumber
lastLoginTime
status
delete
role {
id
tag
}
organizations{
id
tag
}
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
const users = response.data.data.paginateUsers;
dispatch({
type: "GET_USERS",
payload: {
users,
},
});
})
.catch((error) => {
console.log("error -- responsee", error);
});
};
};
export const addUser = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query:
`
mutation {
createUser(input: {
email:"` +
data.email +
`",firstName:"` +
data.firstName +
`",lastName:"` +
data.lastName +
`",password:"` +
data.password +
`",phoneNumber:"` +
data.phoneNumber +
`",status:"` +
data.status +
`",role:"` +
data.role +
`",
organizations:[${data.organizations}]}) {
id
firstName
lastName
email
phoneNumber
status
delete
role {
id
tag
default_role
}
organizations{
id
tag
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "ADD_USER",
payload: {
data: response.data.data.createUser,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const updateUser = (data) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query:
`
mutation {
updateUser(id: "` +
data.id +
`", input: {firstName:"` +
data.firstName +
`",lastName:"` +
data.lastName +
`", email:"` +
data.email +
`", role:"` +
data.role +
`",phoneNumber:"` +
data.phoneNumber +
`",organizations:[${data.organizations}]}) {
id
firstName
lastName
email
phoneNumber
status
delete
role {
id
tag
default_role
}
organizations{
id
tag
}
}
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "UPDATE_USER",
payload: {
data: response.data.data.updateUser,
},
});
})
.catch((error) => {
console.log("error", error);
});
};
};
export const deleteUser = (userId) => {
return async (dispatch) => {
ApplicationService.http()
.post(
"/graphql",
{
query:
`
mutation {
deleteUser(id: "` +
userId +
`")
}
`,
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
}
)
.then((response) => {
dispatch({
type: "DELETE_USER",
payload: {
id: userId,
},
});
})
.catch((error) => {
console.log("error -- responsee", error);
});
};
};

View File

@@ -0,0 +1,15 @@
const initialState = {
data: [],
};
const accessTokenReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_NEWACCESSTOKEN":
return {
...state,
data: action.payload.newAccessToken,
};
}
return state;
};
export default accessTokenReducer;

View File

@@ -0,0 +1,68 @@
const initialState = {
answers: [],
answersWithPaginate: [],
};
const answersReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_ANSWERS":
return {
...state,
answers: action.payload.answers,
};
case "GET_ANSWERS_WITH_PAGINATE":
return {
...state,
answersWithPaginate: action.payload.answersWithPaginate,
};
case "ADD_ANSWER":
return {
...state,
answers: [...state.answers, action.payload.answers],
answersWithPaginate: {
...state.answersWithPaginate,
content: [
...state.answersWithPaginate.content,
action.payload.answers,
],
},
};
case "UPDATE_ANSWER":
return {
...state,
answers: state.answers.map((answer) => {
if (answer.id === action.payload.answers.id) {
return action.payload.answers;
}
return answer;
}),
answersWithPaginate: {
...state.answersWithPaginate,
content: state.answersWithPaginate?.content.map((answer) => {
if (answer.id === action.payload.answers?.id) {
return action.payload.answers;
}
return answer;
}),
},
};
case "DELETE_ANSWER":
return {
...state,
answers: state.answers.filter(
(answer) => answer.id != action.payload.id
),
answersWithPaginate: {
...state.answersWithPaginate,
content: state.answersWithPaginate?.content.filter(
(answer) => answer.id != action.payload.id
),
},
};
}
return state;
};
export default answersReducer;

View File

@@ -0,0 +1,69 @@
const initialState = {
areas: [],
areasWithCriteria: [],
areasWithPaginate: [],
};
const areasReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_AREAS":
return {
...state,
areas: action.payload.areas,
};
case "GET_AREAS_WITH_PAGINATE":
return {
...state,
areasWithPaginate: action.payload.areasWithPaginate,
};
case "GET_AREAS_WITH_CRITERIA":
return {
...state,
areasWithCriteria: action.payload.getAreasWithCriteria,
};
case "ADD_AREA":
return {
...state,
areas: [...state.areas, action.payload.areas],
areasWithPaginate: {
...state.areasWithPaginate,
content: [...state.areasWithPaginate.content, action.payload.areas],
},
};
case "UPDATE_AREA":
return {
...state,
areas: state.areas.map((area) => {
if (area.id === action.payload.areas.id) {
return action.payload.areas;
}
return area;
}),
areasWithPaginate: {
...state.areasWithPaginate,
content: state.areasWithPaginate?.content.map((area) => {
if (area.id === action.payload.areas?.id) {
return action.payload.areas;
}
return area;
}),
},
};
case "DELETE_AREA":
return {
...state,
areas: state.areas.filter((area) => area.id != action.payload.id),
areasWithPaginate: {
...state.areasWithPaginate,
content: state.areasWithPaginate?.content.filter(
(area) => area.id != action.payload.id
),
},
};
}
return state;
};
export default areasReducer;

View File

@@ -0,0 +1,32 @@
const initialState = {
uid: null,
user: null,
isLoggedIn: false,
accessToken: null,
// refreshToken: null,
}
const authReducer = (state = initialState, action) => {
switch (action.type) {
case 'LOGIN':
return {
uid: action.payload.id,
user: action.payload.user,
isLoggedIn: true,
accessToken: action.payload.accessToken,
// refreshToken: action.payload.refreshToken,
}
case 'LOGOUT':
return {
uid: null,
user: null,
isLoggedIn: false,
accessToken: null,
// refreshToken: null,
}
default:
return state
}
}
export default authReducer

View File

@@ -0,0 +1,28 @@
const initialState = {
cities: [],
paginateCities: [],
};
const citiesReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_CITIES":
return {
...state,
cities: action.payload.cities,
};
case "PAGINATE_CITIES":
return {
...state,
paginateCities: action.payload.paginateCities,
};
case "GET_CITIES_WITHOUT_COORDS":
return {
...state,
cities: action.payload.cities,
};
}
return state;
};
export default citiesReducer;

View File

@@ -0,0 +1,15 @@
const initialState = {
city: [],
};
const cityReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_CITY":
return {
...state,
city: action.payload.city,
};
}
return state;
};
export default cityReducer;

View File

@@ -0,0 +1,15 @@
const initialState = {
countries: [],
};
const countriesReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_COUNTRIES":
return {
...state,
countries: action.payload.countries,
};
}
return state;
};
export default countriesReducer;

View File

@@ -0,0 +1,100 @@
const initialState = {
dataCenters: [],
loading: false,
error: null,
creating: false,
createError: null,
updating: false,
updateError: null,
deleting: false,
deleteError: null,
total: 0
};
const dataCenterReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_DATA_CENTERS_LOADING":
return {
...state,
loading: true,
error: null,
};
case "GET_DATA_CENTERS_SUCCESS":
return {
...state,
dataCenters: action.payload.dataCenters,
total: action.payload.total || action.payload.dataCenters.length,
loading: false,
error: null,
};
case "GET_DATA_CENTERS_ERROR":
return {
...state,
loading: false,
error: action.payload.error,
};
case "CREATE_DATA_CENTER_LOADING":
return {
...state,
creating: true,
createError: null,
};
case "CREATE_DATA_CENTER_SUCCESS":
return {
...state,
dataCenters: [...state.dataCenters, action.payload],
creating: false,
createError: null,
};
case "CREATE_DATA_CENTER_ERROR":
return {
...state,
creating: false,
createError: action.payload.error,
};
case "UPDATE_DATA_CENTER_LOADING":
return {
...state,
updating: true,
updateError: null,
};
case "UPDATE_DATA_CENTER_SUCCESS":
return {
...state,
dataCenters: state.dataCenters.map(dc =>
dc.id === action.payload.id ? action.payload : dc
),
updating: false,
updateError: null,
};
case "UPDATE_DATA_CENTER_ERROR":
return {
...state,
updating: false,
updateError: action.payload.error,
};
case "DELETE_DATA_CENTER_LOADING":
return {
...state,
deleting: true,
deleteError: null,
};
case "DELETE_DATA_CENTER_SUCCESS":
return {
...state,
dataCenters: state.dataCenters.filter(dc => dc.id !== action.payload.id),
deleting: false,
deleteError: null,
};
case "DELETE_DATA_CENTER_ERROR":
return {
...state,
deleting: false,
deleteError: action.payload.error,
};
default:
return state;
}
};
export default dataCenterReducer;

View File

@@ -0,0 +1,58 @@
const initialState = {
sectors: [],
sector: [],
subSectors: [],
subSector: [],
activitySubUnits: [],
consuptionUnits: [],
emissionScopes: [],
gpcReferences: [],
mcfTypes: [],
};
const datasReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_SECTORS":
return {
...state,
sectors: action.payload.sectors,
};
case "GET_SECTOR_BY_ID":
return {
...state,
sector: action.payload.sector,
};
case "GET_SUBSECTORS":
return {
...state,
subSectors: action.payload.subSectors,
};
case "GET_SUBSECTOR_BY_ID":
return {
...state,
subSector: action.payload.subSector || {},
};
case "GET_ACTIVITY_SUBUNITS":
return {
...state,
activitySubUnits: action.payload.activitySubUnits,
};
case "GET_CONSUPTION_UNITS":
return {
...state,
consuptionUnits: action.payload.consuptionUnits,
};
case "GET_GPC_REFERENCES":
return {
...state,
gpcReferences: action.payload.gpcReferences,
};
case "GET_MCF_TYPES":
return {
...state,
mcfTypes: action.payload.mcfTypes,
};
}
return state;
};
export default datasReducer;

View File

@@ -0,0 +1,15 @@
const initialState = {
district: [],
};
const districtReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_DISTRICT":
return {
...state,
district: action.payload.district,
};
}
return state;
};
export default districtReducer;

View File

@@ -0,0 +1,15 @@
const initialState = {
districts: [],
};
const districtsReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_DISTRICTS":
return {
...state,
districts: action.payload.districts,
};
}
return state;
};
export default districtsReducer;

View File

@@ -0,0 +1,79 @@
const initialState = {
emissionSources: [],
emissionSourcesWithPaginate: [],
emissionSource: [],
};
const emissionSourceReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_EMISSION_SOURCES":
return {
...state,
emissionSources: action.payload.emissionSources,
};
case "GET_EMISSION_SOURCES_WITH_PAGINATE":
return {
...state,
emissionSourcesWithPaginate: action.payload.emissionSourcesWithPaginate,
};
case "ADD_EMISSION_SOURCE":
return {
...state,
emissionSources: [
...state.emissionSources,
action.payload.emissionSource,
],
emissionSourcesWithPaginate: {
...state.emissionSourcesWithPaginate,
content: [
...state.emissionSourcesWithPaginate.content,
action.payload.emissionSource,
],
},
};
case "UPDATE_EMISSION_SOURCE" || "UPDATE_EMISSION_SOURCE_OF_WASTE":
return {
...state,
emissionSources: [
...state.emissionSources.map((emissionSource) => {
if (emissionSource.id === action.payload.emissionSource.id) {
return action.payload.emissionSource;
}
return emissionSource;
}),
],
emissionSourcesWithPaginate: {
...state.emissionSourcesWithPaginate,
content: state.emissionSourcesWithPaginate?.content.map(
(emissionSource) => {
if (emissionSource.id === action.payload.emissionSource?.id) {
return action.payload.emissionSource;
}
return emissionSource;
}
),
},
};
case "DELETE_EMISSION_SOURCE":
return {
...state,
emissionSources: [
...state.emissionSources.filter(
(emissionSource) => emissionSource.id != action.payload.id
),
],
emissionSourcesWithPaginate: {
...state.emissionSourcesWithPaginate,
content: state.emissionSourcesWithPaginate?.content.filter(
(emissionSource) => emissionSource.id != action.payload.id
),
},
};
default:
return state;
}
};
export default emissionSourceReducer;

View File

@@ -0,0 +1,35 @@
// ** ThemeConfig Import
import themeConfig from "../../../configs/themeConfig";
// ** Returns Initial Menu Collapsed State
const initialMenuCollapsed = () => {
const item = window.localStorage.getItem('menuCollapsed')
//** Parse stored json or if none return initialValue
return item ? JSON.parse(item) : themeConfig.layout.menu.isCollapsed
}
// ** Initial State
const initialState = {
isRTL: themeConfig.layout.isRTL,
menuCollapsed: initialMenuCollapsed(),
menuHidden: themeConfig.layout.menu.isHidden,
contentWidth: themeConfig.layout.contentWidth
}
const layoutReducer = (state = initialState, action) => {
switch (action.type) {
case 'HANDLE_CONTENT_WIDTH':
return { ...state, contentWidth: action.value }
case 'HANDLE_MENU_COLLAPSED':
window.localStorage.setItem('menuCollapsed', action.value)
return { ...state, menuCollapsed: action.value }
case 'HANDLE_MENU_HIDDEN':
return { ...state, menuHidden: action.value }
case 'HANDLE_RTL':
return { ...state, isRTL: action.value }
default:
return state
}
}
export default layoutReducer

View File

@@ -0,0 +1,66 @@
const initialState = {
currentSettings: null,
loading: false,
error: null,
success: false,
}
const mailSettingsReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_MAIL_SETTINGS_PENDING":
return {
...state,
loading: true,
error: null,
}
case "GET_MAIL_SETTINGS_FULFILLED":
return {
...state,
loading: false,
// Even if payload is null, we still want to set loading to false
currentSettings: action.payload || null,
}
case "GET_MAIL_SETTINGS_REJECTED":
return {
...state,
loading: false,
error: action.payload || "Failed to fetch mail settings",
}
case "UPDATE_MAIL_SETTINGS_PENDING":
return {
...state,
loading: true,
error: null,
success: false,
}
case "UPDATE_MAIL_SETTINGS_FULFILLED":
return {
...state,
loading: false,
currentSettings: action.payload,
success: true,
}
case "UPDATE_MAIL_SETTINGS_REJECTED":
return {
...state,
loading: false,
error: action.payload || "Failed to update mail settings",
success: false,
}
case "CLEAR_MAIL_ERROR":
return {
...state,
error: null,
}
case "CLEAR_MAIL_SUCCESS":
return {
...state,
success: false,
}
default:
return state
}
}
export default mailSettingsReducer

View File

@@ -0,0 +1,50 @@
const initialState = {
mainDataTables: [],
mainDataTablesWithPaginate: null,
vmEmissionSummary: null
};
const mainDataTablesReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_MAIN_TABLES":
return {
...state,
mainDataTables: action.payload.mainDataTables,
};
case "GET_MAIN_TABLES_WITH_PAGINATE":
return {
...state,
mainDataTablesWithPaginate: action.payload.mainDataTablesWithPaginate,
};
case "GET_VM_EMISSION_SUMMARY":
return {
...state,
vmEmissionSummary: action.payload.vmEmissionSummary,
};
case "ADD_DATA_INPUT":
return {
...state,
mainDataTables: [...state.mainDataTables, action.payload.dataInput],
};
case "UPDATE_DATA_INPUT":
return {
...state,
mainDataTables: state.mainDataTables.map((data) =>
data.id === action.payload.dataInput.id
? action.payload.dataInput
: data
),
};
case "DELETE_DATA_INPUT":
return {
...state,
mainDataTables: state.mainDataTables.filter(
(data) => data.id !== action.payload.id
),
};
default:
return state;
}
};
export default mainDataTablesReducer;

View File

@@ -0,0 +1,53 @@
const initialState = {
neighborhoods: [],
};
const neighborhoodsReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_NEIGHBORHOODS":
return {
...state,
neighborhoods: action.payload.neighborhoods,
};
case "ADD_NEIGHBORHOOD":
return {
...state,
neighborhoods: {
...state.neighborhoods,
content: [
...state.neighborhoods.content,
action.payload.neighborhoods,
],
},
};
case "UPDATE_NEIGHBORHOOD":
return {
...state,
neighborhoods: {
...state.neighborhoods,
content: state.neighborhoods?.content.map((neighborhood) => {
if (neighborhood.id === action.payload.neighborhoods?.id) {
return action.payload.neighborhoods;
}
return neighborhood;
}),
},
};
case "DELETE_NEIGHBORHOOD":
return {
...state,
neighborhoods: {
...state.neighborhoods,
content: state.neighborhoods?.content.filter(
(neighborhood) => neighborhood.id != action.payload.id
),
},
};
}
return state;
};
export default neighborhoodsReducer;

View File

@@ -0,0 +1,39 @@
const initialState = {
getQuickNotifications: [],
totalForQuick: 0,
notifications: [],
};
const notificationsReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_QUICKNOTIFICATIONS":
return {
...state,
getQuickNotifications: action.payload.getQuickNotifications || [],
totalForQuick: (action.payload.getQuickNotifications || []).filter(
(notification) => notification.read === false
).length,
};
case "GET_SETNOTIFICATIONREAD":
return {
...state,
setNotificationRead: action.payload.setNotificationRead,
//totalForQuick: state.totalForQuick >= 1 ? state.totalForQuick - 1 : 0,
};
case "GET_ALLNOTIFICATION":
return {
...state,
notifications: action.payload.getAllNotifications || [],
};
case "GET_NOTIFICATIONREMOVE":
return {
...state,
notificationRemove: action.payload.notificationRemove,
};
}
return state;
};
export default notificationsReducer;

View File

@@ -0,0 +1,86 @@
const initialState = {
dataOrganization: [],
organizationWithPaginate: [],
organization: [],
total: 0,
};
const organisationReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_ORGANISATIONS":
return {
...state,
dataOrganization: action.payload.organisations,
total: action.payload.organisations.length,
};
case "GET_ORGANIZATIONS_WITH_PAGINATE":
return {
...state,
organizationWithPaginate: action.payload.organizationsWithPaginate,
};
case "GET_ORGANISATION_BY_ID":
return {
...state,
organization: action.payload.organisation,
};
case "ADD_ORGANIZATION":
return {
...state,
dataOrganization: [
...state.dataOrganization,
action.payload.organisation,
],
organizationWithPaginate: {
...state.organizationWithPaginate,
content: [
...state.organizationWithPaginate.content,
action.payload.organisation,
],
},
};
case "UPDATE_ORGANIZATION":
return {
...state,
dataOrganization: [
...state.dataOrganization.map((organisation) => {
if (organisation.id === action.payload.organisation.id) {
return action.payload.organisation;
}
return organisation;
}),
],
organizationWithPaginate: {
...state.organizationWithPaginate,
content: state.organizationWithPaginate?.content.map(
(organization) => {
if (organization.id === action.payload.organisation?.id) {
return action.payload.organisation;
}
return organization;
}
),
},
};
case "DELETE_ORGANIZATION":
return {
...state,
dataOrganization: [
...state.dataOrganization.filter(
(organisation) => organisation.id != action.payload.id
),
],
organizationWithPaginate: {
...state.organizationWithPaginate,
content: state.organizationWithPaginate?.content.filter(
(organization) => organization.id != action.payload.id
),
},
};
default:
return state;
}
};
export default organisationReducer;

View File

@@ -0,0 +1,20 @@
const initialState = {
permissions: [],
};
const permissionsReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_PERMISSIONS":
return {
...state,
permissions: action.payload.permissions,
};
case "GET_USERPERMISSIONS":
return {
...state,
permissions: action.payload.userpermissions,
};
}
return state;
};
export default permissionsReducer;

View File

@@ -0,0 +1,68 @@
const initialState = {
questions: [],
questionsWithPaginate: [],
};
const questionsReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_QUESTİONS":
return {
...state,
questions: action.payload.questions,
};
case "GET_QUESTİONS_WITH_PAGINATE":
return {
...state,
questionsWithPaginate: action.payload.questionsWithPaginate,
};
case "ADD_QUESTİON":
return {
...state,
questions: [...state.questions, action.payload.questions],
questionsWithPaginate: {
...state.questionsWithPaginate,
content: [
...state.questionsWithPaginate.content,
action.payload.questions,
],
},
};
case "UPDATE_QUESTİON":
return {
...state,
questions: state.questions.map((question) => {
if (question.id === action.payload.questions.id) {
return action.payload.questions;
}
return question;
}),
questionsWithPaginate: {
...state.questionsWithPaginate,
content: state.questionsWithPaginate?.content.map((question) => {
if (question.id === action.payload.questions?.id) {
return action.payload.questions;
}
return question;
}),
},
};
case "DELETE_QUESTİON":
return {
...state,
questions: state.questions.filter(
(question) => question.id != action.payload.id
),
questionsWithPaginate: {
...state.questionsWithPaginate,
content: state.questionsWithPaginate?.content.filter(
(question) => question.id != action.payload.id
),
},
};
}
return state;
};
export default questionsReducer;

View File

@@ -0,0 +1,59 @@
const initialState = {
roles: [],
rolesWithPaginate: [],
isError: false,
};
const rolesReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_ROLES":
return {
...state,
roles: action.payload.roles,
isError: action.payload.errorStatus,
};
case "GET_ROLES_WITH_PAGINATE":
return {
...state,
rolesWithPaginate: action.payload.roles,
};
case "ADD_ROLES":
return {
...state,
rolesWithPaginate: {
...state.roles,
content: [...state.rolesWithPaginate.content, action.payload.roles],
},
};
case "UPDATE_ROLES":
return {
...state,
rolesWithPaginate: {
...state.roles,
content: state.rolesWithPaginate?.content.map((role) => {
if (role.id === action.payload.roles?.id) {
return action.payload.roles;
}
return role;
}),
},
};
case "DELETE_ROLES":
return {
...state,
rolesWithPaginate: {
...state.rolesWithPaginate,
content: state.rolesWithPaginate?.content.filter(
(role) => role.id != action.payload.id
),
},
};
}
return state;
};
export default rolesReducer;

View File

@@ -0,0 +1,62 @@
import { combineReducers } from "redux";
import auth from "./auth";
import layout from "./layout";
import users from "./users";
import user from "./user";
import userProfileSettings from "./userProfileSettings";
import organizations from "./organisations";
import rolesReducer from "./roles";
import permissionsReducer from "./permissions";
import systemHistory from "./systemHistory";
import userHistory from "./userHistory";
import areas from "./areas";
import countries from "./country";
import cities from "./cities";
import city from "./city";
import districts from "./districts";
import district from "./district";
import neighborhoods from "./neighborhoods";
import notifications from "./notifications";
import accessToken from "./accessToken";
import emissionSources from "./emissionSources";
import datas from "./datas";
import mainDataTables from "./mainDataTables";
import questions from "./question";
import answers from "./answer";
import surveys from "./surveys";
import uploads from "./upload";
import mailSettings from "./mailSettings";
import dataCenter from "./dataCenter";
const rootReducer = combineReducers({
accessToken,
auth,
layout,
users,
user,
userProfileSettings,
organizations,
rolesReducer,
permissionsReducer,
systemHistory,
userHistory,
areas,
countries,
cities,
city,
districts,
district,
neighborhoods,
notifications,
emissionSources,
datas,
mainDataTables,
questions,
answers,
surveys,
uploads,
mailSettings,
dataCenter,
});
export default rootReducer;

View File

@@ -0,0 +1,127 @@
const initialState = {
publishedSurvey: [],
savedSurveys: [],
survey: [],
surveys: [],
surveysWithPaginate: [],
};
const surveysReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_SURVEY":
return {
...state,
survey: action.payload.survey,
};
case "PUBLİSHED_SURVEY":
return {
...state,
publishedSurvey: action.payload.publishedSurvey,
};
case "GET_SURVEYS_WITH_PAGINATE":
return {
...state,
surveysWithPaginate: action.payload.surveysWithPaginate,
};
case "SAVED_SURVEYS_FROM_SURVEYS":
return {
...state,
savedSurveysFromSurveys: action.payload.savedSurveysFromSurveys,
};
case "SAVED_SURVEYS":
return {
...state,
savedSurveys: action.payload.savedSurveys,
};
case "ADD_SURVEY":
return {
...state,
surveys: [...state.surveys, action.payload.surveys],
surveysWithPaginate: {
...state.surveysWithPaginate,
content: [
...state.surveysWithPaginate.content,
action.payload.surveys,
],
},
};
case "ADD_QUESTION_TO_SURVEY":
return {
...state,
surveys: [
...state.surveys.map((survey) => {
if (survey.id === action.payload.surveys.id) {
return action.payload.survey;
}
return survey;
}),
],
surveysWithPaginate: {
...state.surveysWithPaginate,
content: state.surveysWithPaginate?.content.map((survey) => {
if (survey.id === action.payload.surveys?.id) {
return action.payload.surveys;
}
return survey;
}),
},
};
case "DELETE_QUESTİON_FROM_SURVEY":
return {
...state,
surveys: state.surveys.filter(
(survey) => survey.id != action.payload.id
),
surveysWithPaginate: {
...state.surveysWithPaginate,
content: state.surveysWithPaginate?.content.filter(
(survey) => survey.id != action.payload.id
),
},
};
/*
case "UPDATE_QUESTİON":
return {
...state,
questions: state.questions.map((question) => {
if (question.id === action.payload.questions.id) {
return action.payload.questions;
}
return question;
}),
questionsWithPaginate: {
...state.questionsWithPaginate,
content: state.questionsWithPaginate?.content.map((question) => {
if (question.id === action.payload.questions?.id) {
return action.payload.questions;
}
return question;
}),
},
};
*/
case "DELETE_SURVEY":
return {
...state,
surveys: state.surveys.filter(
(survey) => survey.id != action.payload.id
),
surveysWithPaginate: {
...state.surveysWithPaginate,
content: state.surveysWithPaginate?.content.filter(
(survey) => survey.id != action.payload.id
),
},
};
default:
return state;
}
};
export default surveysReducer;

View File

@@ -0,0 +1,17 @@
const initialState = {
systemHistories: [],
}
const systemHistoryReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_SYSTEMHISTORY":
return {
...state,
systemHistories: action.payload.systemHistories,
}
default:
return state
}
}
export default systemHistoryReducer

View File

@@ -0,0 +1,17 @@
const initialState = {
excelUpload: null,
}
const uploadReducer = (state = initialState, action) => {
switch (action.type) {
case "EXCEL_UPLOAD":
return {
...state,
excelUpload: action.payload.excelUpload,
}
default:
return state
}
}
export default uploadReducer

View File

@@ -0,0 +1,30 @@
const initialState = {
data: [],
};
const UserReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_USER":
return {
...state,
data: action.payload.user,
};
case "UPDATE_USERINFO":
return {
...state,
data: state.data,
};
case "UPDATE_PASSWORD":
return {
...state,
data: state.data,
};
default:
return state;
}
};
export default UserReducer;

View File

@@ -0,0 +1,17 @@
const initialState = {
userhistories: [],
};
const userHistoryReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_USERHISTORY":
return {
...state,
userHistories: action.payload.userhistories,
};
default:
return state;
}
};
export default userHistoryReducer;

View File

@@ -0,0 +1,23 @@
const initialState = {
userProfileSettings: [],
};
const userProfileSettings = (state = initialState, action) => {
switch (action.type) {
case "GET_USERPROFILESETTING":
return {
...state,
userProfileSettings: action.payload.getUserProfileSettings,
};
case "UPDATE_USERPROFILESETTING":
return {
...state,
userProfileSettings: action.payload.data,
};
default:
return state;
}
};
export default userProfileSettings;

View File

@@ -0,0 +1,53 @@
const initialState = {
data: [],
total: 0,
};
const DataTablesReducer = (state = initialState, action) => {
switch (action.type) {
case "GET_USERS":
return {
...state,
data: action.payload.users,
total: action.payload.users?.content?.length,
};
case "ADD_USER":
return {
...state,
data: {
...state.data,
content: [...state.data.content, action.payload.data],
},
total: state.total + 1,
};
case "DELETE_USER":
return {
...state,
data: {
...state.data,
content: state.data?.content.filter(
(user) => user.id != action.payload.id
),
},
total: state.total - 1,
};
case "UPDATE_USER":
return {
...state,
data: {
...state.data,
content: state.data?.content.map((user) => {
if (user.id === action.payload.data?.id) {
return action.payload.data;
}
return user;
}),
},
};
default:
return state;
}
};
export default DataTablesReducer;

View File

@@ -0,0 +1,16 @@
// ** Redux, Thunk & Root Reducer Imports
import thunk from 'redux-thunk'
import createDebounce from 'redux-debounced'
import rootReducer from '../reducers/rootReducer'
import { createStore, applyMiddleware, compose } from 'redux'
// ** init middleware
const middleware = [thunk, createDebounce()]
// ** Dev Tools
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
// ** Create store
const store = createStore(rootReducer, {}, composeEnhancers(applyMiddleware(...middleware)))
export { store }