Skip to content

Commit

Permalink
Melhoria nas rotas da Personalização
Browse files Browse the repository at this point in the history
  • Loading branch information
rtenorioh committed Dec 2, 2024
1 parent 3e071d7 commit 5ac3ea7
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 35 deletions.
30 changes: 23 additions & 7 deletions backend/api.rest
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#Variaveis
@baseUrl = http://localhost:8080
@token = 6175c0d0-acd5-4776-95a9-592c795da986
@token2 = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IlByZXNzIFRpY2tldCIsInByb2ZpbGUiOiJhZG1pbiIsImlkIjoxLCJpYXQiOjE3MzI4ODUzMzQsImV4cCI6MTczMjg4ODkzNH0.4MSoKumH6IT2loUzdlm9OwKzy8BOohcAkMBv6j6Ho4o
@token2 = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Ik1hc3RlckFkbWluIiwicHJvZmlsZSI6Im1hc3RlcmFkbWluIiwiaWQiOjIsImlhdCI6MTczMzEzNjUxOCwiZXhwIjoxNzMzMTQwMTE4fQ.UOA-goHaIATCvMs_eAXIIR6bjEBuOg1VbF40Q2zxUn0

@refreshToken = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidG9rZW5WZXJzaW9uIjowLCJpYXQiOjE3MzI4ODUzMzQsImV4cCI6MTczMzQ5MDEzNH0.RwuRIufYUB9dQZQg0aeaVtnOryn-sESNL1mFlShmBM4

Expand All @@ -12,8 +12,8 @@ POST {{baseUrl}}/auth/login
Content-Type: application/json

{
"email": "admin@pressticket.com.br",
"password": "admin"
"email": "masteradmin@pressticket.com.br",
"password": "masteradmin"
}

### Teste da Rota POST /auth/refresh_token
Expand All @@ -38,18 +38,34 @@ Content-Type: application/json
GET {{baseUrl}}/personalizations
Content-Type: application/json

### (Criar ou Atualizar Personalização) Teste da Rota PUT /personalizations/:theme
PUT {{baseUrl}}/personalizations/dark
### (Criar ou Atualizar Dados da Empresa) Teste da Rota PUT /personalizations/:theme/company
PUT {{baseUrl}}/personalizations/light/company
Authorization: Bearer {{token2}}
Content-Type: application/json

{
"company": "Press Ticket",
"url": "https://pressticket.com.br",
"url": "https://pressticket.com.br"
}

### (Criar ou Atualizar Cores) Teste da Rota PUT /personalizations/:theme/colors
PUT {{baseUrl}}/personalizations/light/colorS
Authorization: Bearer {{token2}}
Content-Type: application/json

{
"primaryColor": "#ffffff",
"secondaryColor": "#0000ff",
"backgroundDefault": "#ff00ff",
"backgroundPaper": "#00ff00",
"backgroundPaper": "#00ff00"
}

### (Criar ou Atualizar Logos) Teste da Rota PUT /personalizations/:theme/logos
PUT {{baseUrl}}/personalizations/light/logos
Authorization: Bearer {{token2}}
Content-Type: application/json

{
"favico": "teste.ico",
"logo": null,
"logoTicket": null
Expand Down
81 changes: 72 additions & 9 deletions backend/src/controllers/PersonalizationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,54 @@ interface PersonalizationData {
theme: string;
company?: string;
url?: string;
primaryColor: string;
secondaryColor: string;
backgroundDefault: string;
backgroundPaper: string;
primaryColor?: string;
secondaryColor?: string;
backgroundDefault?: string;
backgroundPaper?: string;
favico?: string | null;
logo?: string | null;
logoTicket?: string | null;
}

export const createOrUpdate = async (
export const createOrUpdateCompany = async (
req: Request,
res: Response
): Promise<Response> => {
try {
const personalizationData: PersonalizationData = req.body;
const { theme } = req.params;
const { company, url } = req.body;

const personalizationData = { theme, company, url };

const personalization = await createOrUpdatePersonalization({
personalizationData,
theme
});

const io = getIO();
io.emit("personalization", {
action: personalization.isNew ? "create" : "update",
personalization: personalization.data
});

return res.status(200).json(personalization.data);
} catch (error) {
return res.status(500).json({ message: error.message });
}
};

export const createOrUpdateLogos = async (
req: Request,
res: Response
): Promise<Response> => {
try {
const { theme } = req.params;
const personalizationData: PersonalizationData = {
theme
};

if (req.files) {
const files = req.files as {
[fieldname: string]: Express.Multer.File[];
};
const files = req.files as { [fieldname: string]: Express.Multer.File[] };

if (files.favico && files.favico.length > 0) {
personalizationData.favico = path.basename(files.favico[0].path);
Expand All @@ -44,6 +71,42 @@ export const createOrUpdate = async (
}
}

personalizationData.theme = theme;

const personalization = await createOrUpdatePersonalization({
personalizationData,
theme
});

const io = getIO();
io.emit("personalization", {
action: personalization.isNew ? "create" : "update",
personalization: personalization.data
});

return res.status(200).json(personalization.data);
} catch (error) {
return res.status(500).json({ message: error.message });
}
};

export const createOrUpdateColors = async (
req: Request,
res: Response
): Promise<Response> => {
try {
const { theme } = req.params;
const { primaryColor, secondaryColor, backgroundDefault, backgroundPaper } =
req.body;

const personalizationData: PersonalizationData = {
theme,
primaryColor,
secondaryColor,
backgroundDefault,
backgroundPaper
};

const personalization = await createOrUpdatePersonalization({
personalizationData,
theme
Expand Down
22 changes: 17 additions & 5 deletions backend/src/routes/personalizationRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,32 @@ import isAuth from "../middleware/isAuth";
const personalizationRoutes = Router();

personalizationRoutes.get("/personalizations", PersonalizationController.list);
personalizationRoutes.put(
personalizationRoutes.delete(
"/personalizations/:theme",
isAuth,
PersonalizationController.remove
);
personalizationRoutes.put(
"/personalizations/:theme/company",
isAuth,
PersonalizationController.createOrUpdateCompany
);

personalizationRoutes.put(
"/personalizations/:theme/logos",
isAuth,
uploadConfig.fields([
{ name: "favico", maxCount: 1 },
{ name: "logo", maxCount: 1 },
{ name: "logoTicket", maxCount: 1 }
]),
PersonalizationController.createOrUpdate
PersonalizationController.createOrUpdateLogos
);
personalizationRoutes.delete(
"/personalizations/:theme",

personalizationRoutes.put(
"/personalizations/:theme/colors",
isAuth,
PersonalizationController.remove
PersonalizationController.createOrUpdateColors
);

export default personalizationRoutes;
6 changes: 3 additions & 3 deletions frontend/src/pages/Settings/Personalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const PersonalizeSettings = ({ onThemeConfigUpdate }) => {
url: data.url,
};
try {
await api.put("/personalizations/light", payload);
await api.put("/personalizations/light/company", payload);
toast.success("Dados da empresa salvos com sucesso!");
} catch (err) {
toast.error("Erro ao salvar dados da empresa");
Expand All @@ -210,7 +210,7 @@ const PersonalizeSettings = ({ onThemeConfigUpdate }) => {
formData.append(type, file);

try {
const response = await api.put(`/personalizations/${theme}`, formData, {
const response = await api.put(`/personalizations/${theme}/logos`, formData, {
headers: { "Content-Type": "multipart/form-data" },
});

Expand Down Expand Up @@ -273,7 +273,7 @@ const PersonalizeSettings = ({ onThemeConfigUpdate }) => {
};

try {
const response = await api.put(`/personalizations/${theme}`, payload);
const response = await api.put(`/personalizations/${theme}/colors`, payload);

if (response.status === 200) {
toast.success(`Cores do tema ${theme} salvas com sucesso!`);
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/pages/Settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,20 @@ const Settings = ({ onThemeConfigUpdate }) => {
onChange={handleTabChange}
className={classes.tabs}
>
<Tab label={i18n.t("settings.title")} />
{(!isMasterAdminEnabled || user.profile === "masteradmin") && (
<Tab label="Personalização" />
)}
<Tab label={i18n.t("settings.title")} />
</Tabs>
<Box p={3}>
{tabValue === 0 && (
{tabValue === 0 && (!isMasterAdminEnabled || user.profile === "masteradmin") && (
<Container className={classes.container}>
<ErrorBoundary>
<Personalize onThemeConfigUpdate={onThemeConfigUpdate} />
</ErrorBoundary>
</Container>
)}
{tabValue === 1 && (
<Container className={classes.container}>
<ErrorBoundary>
<ComponentSettings
Expand All @@ -145,13 +152,6 @@ const Settings = ({ onThemeConfigUpdate }) => {
</ErrorBoundary>
</Container>
)}
{tabValue === 1 && (!isMasterAdminEnabled || user.profile === "masteradmin") && (
<Container className={classes.container}>
<ErrorBoundary>
<Personalize onThemeConfigUpdate={onThemeConfigUpdate} />
</ErrorBoundary>
</Container>
)}
</Box>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/translate/languages/pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ const messages = {
},
settings: {
success: "Configurações salvas com sucesso.",
title: "Configurações",
title: "Gerais",
settings: {
userCreation: {
name: "Criação de atendente",
Expand All @@ -579,7 +579,7 @@ const messages = {
},
allTicket: {
name: "Todos podem ver o chamado sem departamento",
note: "Ative essa função para deixar todos os usuarios verem os chamados sem setor",
note: "Ative essa função para deixar todos os usuários verem os chamados sem setor",
options: {
enabled: "Ativado",
disabled: "Desativado",
Expand Down

0 comments on commit 5ac3ea7

Please sign in to comment.