feat: initial commit

This commit is contained in:
Mohamed Marrouchi
2024-09-10 10:50:11 +01:00
commit 30e5766487
879 changed files with 122820 additions and 0 deletions

29
frontend/src/utils/Jwt.ts Normal file
View File

@@ -0,0 +1,29 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
import { TJwtPayload } from "@/types/jwt.types";
export class JWT<T extends TJwtPayload> {
decode(token: string): T {
try {
const base64Url = token.split(".")[1];
const base64 = base64Url?.replace("-", "+").replace("_", "/");
return JSON.parse(window.atob(base64));
} catch (e) {
throw new Error("Invalid Token");
}
}
isExpired({ exp }: T): boolean {
if (exp) return exp < Date.now() / 1000;
return true;
}
}

View File

@@ -0,0 +1,15 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
import { SxProps, Theme } from "@mui/material";
export const SXStyleOptions =
(args: SxProps<Theme>) =>
({ theme }: { theme: Theme }) =>
theme.unstable_sx(args);

28
frontend/src/utils/URL.ts Normal file
View File

@@ -0,0 +1,28 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
export const getFromQuery = ({
key,
search,
defaultValue = "",
}: {
key: string;
search?: string;
defaultValue?: string;
}) => {
try {
const paramsString = search || window.location.search;
const searchParams = new URLSearchParams(paramsString);
const loadCampaign = searchParams.get(key) || defaultValue;
return loadCampaign;
} catch (e) {
return defaultValue;
}
};

View File

@@ -0,0 +1,37 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
import { FileType } from "@/types/message.types";
export const MIME_TYPES = {
images: ["image/jpeg", "image/png", "image/gif", "image/webp"],
videos: ["video/mp4", "video/webm", "video/ogg"],
audios: ["audio/mpeg", "audio/ogg", "audio/wav"],
documents: [
"application/pdf",
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/vnd.ms-powerpoint",
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
],
};
export function getFileType(mimeType: string): FileType {
if (mimeType.startsWith("image/")) {
return FileType.image;
} else if (mimeType.startsWith("video/")) {
return FileType.video;
} else if (mimeType.startsWith("audio/")) {
return FileType.audio;
} else {
return FileType.file;
}
}

122
frontend/src/utils/chart.ts Normal file
View File

@@ -0,0 +1,122 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
import { ColumnChartProps, MultiLineChartProps } from "eazychart-react";
import { Legend } from "@/app-components/chart/Legend";
import { Tooltip } from "@/app-components/chart/Tootip";
import { IBotStat, LineChartStats } from "@/types/bot-stat.types";
const buildFormatDateTicks = (lang: string) => (dateNumber: number) =>
`${new Date(dateNumber).toLocaleDateString(lang, {
month: "short",
weekday: "short",
day: "numeric",
})}`;
const COMMON_CHART_PROPS = {
padding: {
top: 25,
left: 100,
right: 50,
bottom: 100,
},
animationOptions: {
delay: 0,
duration: 400,
easing: "easeBack",
},
scopedSlots: {
TooltipComponent: Tooltip,
LegendComponent: Legend,
},
};
export const buildMultiLineChartConfig =
(lang: string) =>
({
data,
domainKeys,
...rest
}: MultiLineChartProps): MultiLineChartProps => ({
...COMMON_CHART_PROPS,
colors: ["#1AA089", "#Ab1151", "#E6A23c"],
marker: {
hidden: false,
radius: 5,
color: "#FFF",
},
data,
xAxis: {
domainKey: "day",
nice: 0.2,
tickFormat: buildFormatDateTicks(lang),
},
yAxis: {
domainKeys,
nice: 1,
title: "",
},
...rest,
});
export const buildColumnChartConfig = ({
data,
...rest
}: ColumnChartProps): ColumnChartProps => ({
...COMMON_CHART_PROPS,
colors: ["#1AA089", "#ab1151", "#e6a23c", "#57006f", "#108aa8"],
data,
xAxis: {
domainKey: "id",
nice: 0.5,
},
yAxis: {
domainKey: "value",
nice: 2,
title: "",
},
...rest,
});
export const transformToLine = (data: LineChartStats[] | undefined) => {
if (!data) {
return {
data: [],
domainKeys: [],
};
}
const values = data.reduce((acc, curr) => {
return acc.concat(curr.values);
}, [] as IBotStat[]);
const domain = new Set<string>();
const dict = values.reduce((acc, curr) => {
domain.add(curr.name);
acc[curr.day] = {
...(acc[curr.day] || { day: +new Date(curr.day) }),
[curr.name]: curr.value,
};
return acc;
}, {} as Record<string, any>);
Object.values(dict).forEach((dayObj) => {
domain.forEach((key) => {
if (!(key in dayObj)) {
dayObj[key] = null;
}
});
});
return {
data: Object.values(dict).sort((a, b) => a.day - b.day),
domainKeys: Array.from(domain),
};
};

View File

@@ -0,0 +1,17 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
import { DATE_TIME_FORMAT } from "../constants";
export const getDateTimeFormatter = (date: Date) => ({
date,
formatParams: {
val: DATE_TIME_FORMAT,
},
});

View File

@@ -0,0 +1,19 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
export const generateId = () => {
const d =
typeof performance === "undefined" ? Date.now() : performance.now() * 1000;
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
const r = (Math.random() * 16 + d) % 16 | 0;
return (c == "x" ? r : (r & 0x3) | 0x8).toString(16);
});
};

View File

@@ -0,0 +1,17 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
import { FULL_WIDTH_PATHNAMES, TRouterValues } from "@/services/types";
type TLayout = "default" | "full_width";
export const getLayout = (pathname: string): TLayout =>
FULL_WIDTH_PATHNAMES.includes(pathname as TRouterValues)
? "full_width"
: "default";

View File

@@ -0,0 +1,42 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
function isObject(item: any): item is Record<string, any> {
return item && typeof item === "object" && !Array.isArray(item);
}
export function merge<
T extends Record<string, any>,
U extends Record<string, any>,
>(target: T, source: U): T & U {
const output: Record<string, any> = { ...target };
if (isObject(target) && isObject(source)) {
Object.keys(source).forEach((key) => {
if (Array.isArray(source[key])) {
if (Array.isArray(target[key])) {
// Merge arrays uniquely
output[key] = Array.from(new Set([...target[key], ...source[key]]));
} else {
output[key] = source[key];
}
} else if (isObject(source[key])) {
if (!(key in target)) {
output[key] = source[key];
} else {
output[key] = merge(target[key], source[key]);
}
} else {
output[key] = source[key];
}
});
}
return output as T & U;
}

View File

@@ -0,0 +1,17 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
export const slugify = (str: string) => {
return str
.replace(/^\s+|\s+$/g, "")
.toLowerCase()
.replace(/[^a-z0-9 -]/g, "")
.replace(/\s+/g, "-")
.replace(/-+/g, "_");
};

View File

@@ -0,0 +1,19 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
import { generateId } from "./generateId";
export type ValueWithId<T> = {
id: string;
value: T;
};
export const createValueWithId = <T>(value: T): ValueWithId<T> => {
return { id: generateId(), value };
};