Compare commits
15 Commits
57c5deb3bd
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| e7a94b93f1 | |||
| fccaa44e9c | |||
| 421a8b5582 | |||
| 546b66c972 | |||
| d96bde5963 | |||
| 69e6e659e0 | |||
| 86f5422828 | |||
| db6981cad5 | |||
| f200f91f93 | |||
| 06aac5b126 | |||
| 80d9f5d428 | |||
| ad44e775e2 | |||
| cebb34c88a | |||
| 0095bd884a | |||
| c238f28179 |
@@ -0,0 +1,33 @@
|
||||
---
|
||||
name: engram-cloud-sync
|
||||
description: "Trigger: sync engram cloud, sincronizar memoria, push engram, engram cloud sync. Synchronize local Engram project to remote cloud server."
|
||||
license: Apache-2.0
|
||||
metadata:
|
||||
author: "horacio"
|
||||
version: "1.0"
|
||||
---
|
||||
|
||||
## Activation Contract
|
||||
|
||||
Load this skill whenever the user explicitly asks to synchronize, push, or sync their Engram memory with the cloud.
|
||||
|
||||
## Hard Rules
|
||||
|
||||
- **Never skip the sync** when requested. Execute `engram sync --cloud --project turnosxpress` every time.
|
||||
- **Always verify** the cloud server is reachable and the project is enrolled before syncing.
|
||||
- **Report results to the user**: sessions, observations, prompts, mutations exported.
|
||||
- **Fail fast** on 403/forbidden errors — that means the project needs enrollment first.
|
||||
|
||||
## Execution Steps
|
||||
|
||||
1. **Check cloud status:** `engram cloud status --cwd <repo>` (default: current project directory). If `Auth status: ready` and `Sync readiness: pending`, continue.
|
||||
2. **If project is not enrolled** (`403: forbidden: project is not allowed` or similar), run `engram cloud enroll turnosxpress --cwd <repo>` then re-check status.
|
||||
3. **Execute sync:** `engram sync --cloud --project turnosxpress --cwd <repo>`.
|
||||
4. **Report results** — sessions, observations, prompts, mutations count. If sync fails, surface the exact error and suggest running `engram serve` for autosync mode.
|
||||
|
||||
## Output Contract
|
||||
|
||||
Return:
|
||||
- Cloud server URL and enrollment status.
|
||||
- Export counts: sessions, observations, prompts, mutations.
|
||||
- Confirmation: "Cloud sync complete" or actionable error if it failed.
|
||||
+1
-1
@@ -45,7 +45,7 @@ MP_SUBSCRIPTION_FIND_URL = https://api.mercadopago.com/preapproval/
|
||||
MP_ACCESS_TOKEN = APP_USR-8753424836448507-121412-731599daea1ffa0b278b5dcc78aa1ec8-1611134648
|
||||
MP_BACK_URL = https://turnosxpress.com.ar/landing/dashboard
|
||||
MP_CHECK_PAYMENT_MINUTES = 1
|
||||
MP_WEBHOOK_URL = https://30e1-186-132-147-13.ngrok-free.app/mercadopago/webhook
|
||||
MP_WEBHOOK_URL = https://5f09-186-58-32-217.ngrok-free.app/mercadopago/webhook
|
||||
|
||||
DEFAULT_BOT_ADMIN_PORT = 3005
|
||||
|
||||
|
||||
@@ -380,4 +380,5 @@ export interface ICompaniesManager {
|
||||
sysAdminUpdate(data: SysAdminUpdateCompanyParams): Promise<void>;
|
||||
sysAdminSetBanned(data: SysAdminSetCompanyBannedParams): Promise<void>;
|
||||
sysAdminGetInsights(data: SysAdminCompanyInsightsParams): Promise<SysAdminCompanyInsightsResult>;
|
||||
checkCompanyAdmin(data: { companyId: string; sessionUser: string }): Promise<boolean>;
|
||||
}
|
||||
|
||||
@@ -1221,6 +1221,19 @@ class CompaniesManager implements ICompaniesManager {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
public async checkCompanyAdmin(data: { companyId: string; sessionUser: string }): Promise<boolean> {
|
||||
const filterData =
|
||||
data.companyId.indexOf("-") >= 0 ? { slug: data.companyId } : { _id: data.companyId };
|
||||
|
||||
const company = await this.companies.findOne(filterData as any);
|
||||
|
||||
if (!company) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return await EmployeesList.checkPermission(company, data.sessionUser, EmployeeRoles.ADMIN);
|
||||
}
|
||||
}
|
||||
|
||||
const CompaniesList = new CompaniesManager();
|
||||
|
||||
@@ -112,7 +112,6 @@ export class PlanUsageCycleAdapterMongoose implements IPlanUsageCycleAdapter {
|
||||
planId: data.planId,
|
||||
cycleStart: data.cycleStart,
|
||||
cycleEnd: data.cycleEnd,
|
||||
appointmentsCount: 0,
|
||||
creationDate: now,
|
||||
},
|
||||
$inc: { appointmentsCount: data.quantity },
|
||||
|
||||
@@ -38,7 +38,7 @@ export class ToggleCompanyFixedPostController extends Controller {
|
||||
@SuccessResponse(200, "Done")
|
||||
@Post()
|
||||
public async toggleFixedCompanyPost(
|
||||
@Body() requestBody: FixCompanyPostParams
|
||||
@Body() requestBody: FixCompanyPostParams,
|
||||
): Promise<ApiVoidResult | ApiValidationError> {
|
||||
try {
|
||||
await new CompaniesService().toggleFixedPost(requestBody);
|
||||
@@ -62,7 +62,7 @@ export class MoveCompanyFixedPostController extends Controller {
|
||||
@SuccessResponse(200, "Done")
|
||||
@Post()
|
||||
public async moveFixedCompanyPost(
|
||||
@Body() requestBody: MoveCompanyFixedPostParams
|
||||
@Body() requestBody: MoveCompanyFixedPostParams,
|
||||
): Promise<ApiVoidResult | ApiValidationError> {
|
||||
try {
|
||||
await new CompaniesService().moveFixedPost(requestBody);
|
||||
@@ -86,7 +86,7 @@ export class SetNotificationsStatusCompanyController extends Controller {
|
||||
@SuccessResponse(200, "Done")
|
||||
@Post()
|
||||
public async setNotificationAuto(
|
||||
@Body() requestBody: SetNotificationAutoParams
|
||||
@Body() requestBody: SetNotificationAutoParams,
|
||||
): Promise<ApiVoidResult | ApiValidationError> {
|
||||
try {
|
||||
await new CompaniesService().setNotificationAuto(requestBody);
|
||||
@@ -110,7 +110,7 @@ export class SetPublishedStatusCompanyController extends Controller {
|
||||
@SuccessResponse(200, "Done")
|
||||
@Post()
|
||||
public async setPublishedStatus(
|
||||
@Body() requestBody: SetOrganizationPublishedStatusParams
|
||||
@Body() requestBody: SetOrganizationPublishedStatusParams,
|
||||
): Promise<ApiVoidResult | ApiValidationError> {
|
||||
try {
|
||||
await new CompaniesService().setPublishedStatus(requestBody);
|
||||
@@ -134,7 +134,7 @@ export class CreateCompanyController extends Controller {
|
||||
@SuccessResponse(200, "La compañia fue creada con exito")
|
||||
@Post()
|
||||
public async createCompany(
|
||||
@Body() requestBody: CreateCompanyParams
|
||||
@Body() requestBody: CreateCompanyParams,
|
||||
): Promise<ICompany | ApiValidationError> {
|
||||
try {
|
||||
const company = await new CompaniesService().createCompany(requestBody);
|
||||
@@ -155,7 +155,7 @@ export class DeleteCompanyController extends Controller {
|
||||
@SuccessResponse(200, "La compañia fue modificada con exito")
|
||||
@Post()
|
||||
public async deleteCompany(
|
||||
@Body() requestBody: DeleteCompanyParams
|
||||
@Body() requestBody: DeleteCompanyParams,
|
||||
): Promise<ApiVoidResult | ApiValidationError> {
|
||||
try {
|
||||
await new CompaniesService().deleteCompany(requestBody);
|
||||
@@ -179,7 +179,7 @@ export class UpdateCompanyController extends Controller {
|
||||
@SuccessResponse(200, "La compañia fue modificada con exito")
|
||||
@Post()
|
||||
public async updateCompany(
|
||||
@Body() requestBody: UpdateCompanyParams
|
||||
@Body() requestBody: UpdateCompanyParams,
|
||||
): Promise<ApiVoidResult | ApiValidationError> {
|
||||
try {
|
||||
await new CompaniesService().updateCompany(requestBody);
|
||||
@@ -202,7 +202,7 @@ export class GetCompanyByIdController extends Controller {
|
||||
@SuccessResponse(200, "Done")
|
||||
@Post()
|
||||
public async getById(
|
||||
@Body() requestBody: OranizationsViewByIdParams
|
||||
@Body() requestBody: OranizationsViewByIdParams,
|
||||
): Promise<MyOranizationsView | ApiValidationError> {
|
||||
try {
|
||||
const companies = await new CompaniesService().getById(requestBody);
|
||||
@@ -222,7 +222,7 @@ export class GetCompanyByUserController extends Controller {
|
||||
@SuccessResponse(200, "Done")
|
||||
@Post()
|
||||
public async getByUserId(
|
||||
@Body() requestBody: MyOranizationsViewParams
|
||||
@Body() requestBody: MyOranizationsViewParams,
|
||||
): Promise<MyOranizationsView[] | ApiValidationError> {
|
||||
try {
|
||||
const companies = await new CompaniesService().getByUserId(requestBody);
|
||||
@@ -242,7 +242,7 @@ export class PaginateCompanyController extends Controller {
|
||||
@SuccessResponse(200, "Done")
|
||||
@Post()
|
||||
public async paginateUsers(
|
||||
@Body() requestBody: PaginateCompaniesParams
|
||||
@Body() requestBody: PaginateCompaniesParams,
|
||||
): Promise<PaginateCompaniesResults | ApiValidationError> {
|
||||
try {
|
||||
const users = await new CompaniesService().paginateCompanies(requestBody);
|
||||
@@ -265,7 +265,7 @@ export class UploadCompanyHeaderController extends Controller {
|
||||
public async uploadHeader(
|
||||
@FormField() companyId: string,
|
||||
@FormField() sessionUser: string,
|
||||
@UploadedFile() file: Express.Multer.File
|
||||
@UploadedFile() file: Express.Multer.File,
|
||||
): Promise<ApiVoidResult | ApiValidationError> {
|
||||
try {
|
||||
await new CompaniesService().setCompanyHeader({
|
||||
@@ -295,7 +295,7 @@ export class UploadCompanyIconController extends Controller {
|
||||
public async uploadIcon(
|
||||
@FormField() companyId: string,
|
||||
@FormField() sessionUser: string,
|
||||
@UploadedFile() file: Express.Multer.File
|
||||
@UploadedFile() file: Express.Multer.File,
|
||||
): Promise<ApiVoidResult | ApiValidationError> {
|
||||
try {
|
||||
await new CompaniesService().setCompanyIcon({
|
||||
@@ -325,7 +325,7 @@ export class DeleteCompanyHeaderController extends Controller {
|
||||
@SuccessResponse(200, "El archivo fue cargado con exito")
|
||||
@Post()
|
||||
public async deleteHeader(
|
||||
@Body() data: DeleteCompanyFileParams
|
||||
@Body() data: DeleteCompanyFileParams,
|
||||
): Promise<ApiVoidResult | ApiValidationError> {
|
||||
try {
|
||||
await new CompaniesService().deleteCompanyHeader(data);
|
||||
@@ -349,7 +349,7 @@ export class DeleteCompanyIconController extends Controller {
|
||||
@SuccessResponse(200, "El archivo fue cargado con exito")
|
||||
@Post()
|
||||
public async deleteIcon(
|
||||
@Body() data: DeleteCompanyFileParams
|
||||
@Body() data: DeleteCompanyFileParams,
|
||||
): Promise<ApiVoidResult | ApiValidationError> {
|
||||
try {
|
||||
await new CompaniesService().deleteCompanyIcon(data);
|
||||
@@ -372,7 +372,7 @@ export class filterAllOrganizationsController extends Controller {
|
||||
@SuccessResponse(200, "Done")
|
||||
@Post()
|
||||
public async filterAllOrganizations(
|
||||
@Body() requestBody: PaginateCompaniesParams
|
||||
@Body() requestBody: PaginateCompaniesParams,
|
||||
): Promise<TextObjectFilterResult[] | ApiValidationError> {
|
||||
try {
|
||||
const clients = await new CompaniesService().filterAll(requestBody);
|
||||
@@ -392,7 +392,7 @@ export class CheckCompanyNameController extends Controller {
|
||||
@SuccessResponse(200, "Done")
|
||||
@Post()
|
||||
public async checkName(
|
||||
@Body() requestBody: { name: string }
|
||||
@Body() requestBody: { name: string },
|
||||
): Promise<{ valid: boolean } | ApiValidationError> {
|
||||
try {
|
||||
const valid = await new CompaniesService().checkNameExists(requestBody.name);
|
||||
@@ -405,3 +405,24 @@ export class CheckCompanyNameController extends Controller {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Route("companies/check-admin")
|
||||
@Middlewares(authenticateMiddleware)
|
||||
export class CheckCompanyAdminController extends Controller {
|
||||
@Response<ApiValidationError>(500, "Ha ocurrido un error")
|
||||
@SuccessResponse(200, "Done")
|
||||
@Post()
|
||||
public async checkAdmin(
|
||||
@Body() requestBody: { companyId: string; sessionUser: string },
|
||||
): Promise<boolean | ApiValidationError> {
|
||||
try {
|
||||
const isAdmin = await new CompaniesService().checkCompanyAdmin(requestBody);
|
||||
this.setStatus(200);
|
||||
return isAdmin;
|
||||
} catch (e) {
|
||||
const errorOccurred: Error = e as Error;
|
||||
this.setStatus(500);
|
||||
return new ApiValidationError(500, errorOccurred.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,4 +112,9 @@ export class CompaniesService {
|
||||
const isValid = await CompaniestList.isValidName({ name });
|
||||
return isValid;
|
||||
}
|
||||
|
||||
public async checkCompanyAdmin(data: { companyId: string; sessionUser: string }): Promise<boolean> {
|
||||
await connect(`${process.env.DATABASE_CONNECTION}`);
|
||||
return await CompaniestList.checkCompanyAdmin(data);
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
@@ -0,0 +1,19 @@
|
||||
import ApiRequest from "@services/Api.Service";
|
||||
import { UpdateCompanyParams } from "@models/Company.model";
|
||||
import { ApiVoidResult } from "@models/Api.VoidResult.type";
|
||||
|
||||
export const updateOrganizationColors = async (data: UpdateCompanyParams): Promise<ApiVoidResult> => {
|
||||
return ApiRequest.post<ApiVoidResult>("companies/update", data);
|
||||
};
|
||||
|
||||
export const uploadHeaderImage = async (data: FormData): Promise<ApiVoidResult> => {
|
||||
return ApiRequest.postFile<ApiVoidResult>("companies/upload-header", data);
|
||||
};
|
||||
|
||||
export const uploadServiceImage = async (data: FormData): Promise<ApiVoidResult> => {
|
||||
return ApiRequest.postFile<ApiVoidResult>("services/upload-image", data);
|
||||
};
|
||||
|
||||
export const checkOrgAdmin = async (companyId: string, sessionUser: string): Promise<boolean> => {
|
||||
return ApiRequest.post<boolean>("companies/check-admin", { companyId, sessionUser });
|
||||
};
|
||||
+1
-1
@@ -37,7 +37,7 @@ const schemaAppointmentUpdate = Yup.object().shape({
|
||||
start: Yup.string().required("Debe seleccionar una fecha."),
|
||||
price: Yup.number().positive().required("Debe introducir un precio valido."),
|
||||
length: Yup.number().positive().required("Debe introducir una duración."),
|
||||
comments: Yup.string().required("Debe introducir un comentario."),
|
||||
comments: Yup.string().notRequired(),
|
||||
sessionUser: Yup.string().required("Para crear un turno debe iniciar sesión."),
|
||||
});
|
||||
|
||||
|
||||
+1
@@ -1,5 +1,6 @@
|
||||
.movementsPage {
|
||||
padding: 16px;
|
||||
padding-top: 200px;
|
||||
padding-bottom: 32px;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
"use client";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { LineChart } from "@mui/x-charts/LineChart";
|
||||
import { MyOranizationsView } from "@core/Models/Company.model";
|
||||
import { DashboardFinancialsResult, getDashboardFinancials } from "../../landing/dashboard/Dashboard.Service";
|
||||
import {
|
||||
DashboardFinancialsResult,
|
||||
getDashboardFinancials,
|
||||
} from "../../landing/dashboard/Dashboard.Service";
|
||||
import { loadCollaboratorsByCompanyId } from "../../admin/(organization-profile)/org/profile/[id]/collaborators/Collaborators.Service";
|
||||
import { CompanyEmployeesView } from "@models/Collaborators.model";
|
||||
import UnpaidIncomeCard from "../UnpaidIncomeCard/UnpaidIncomeCard";
|
||||
import styles from "./FinancialWidget.module.css";
|
||||
import dayjs from "dayjs";
|
||||
import OpenInNewOutlinedIcon from "@mui/icons-material/OpenInNewOutlined";
|
||||
import { useNavigation } from "@core/app/hooks/goto";
|
||||
|
||||
export interface FinancialWidgetProps {
|
||||
sessionUser: string;
|
||||
@@ -15,7 +19,12 @@ export interface FinancialWidgetProps {
|
||||
organizationName?: string;
|
||||
}
|
||||
|
||||
export default function FinancialWidget({ sessionUser, selectedOrgId, organizationName }: FinancialWidgetProps) {
|
||||
export default function FinancialWidget({
|
||||
sessionUser,
|
||||
selectedOrgId,
|
||||
organizationName,
|
||||
}: FinancialWidgetProps) {
|
||||
const { goTo } = useNavigation();
|
||||
const [selectedTimeframe, setSelectedTimeframe] = useState<"week" | "month" | "year">("month");
|
||||
const [selectedEmployeeId, setSelectedEmployeeId] = useState<string>("");
|
||||
const [collaborators, setCollaborators] = useState<CompanyEmployeesView[]>([]);
|
||||
@@ -27,10 +36,12 @@ export default function FinancialWidget({ sessionUser, selectedOrgId, organizati
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedOrgId) {
|
||||
loadCollaboratorsByCompanyId({ companyId: selectedOrgId }).then((res) => {
|
||||
loadCollaboratorsByCompanyId({ companyId: selectedOrgId })
|
||||
.then((res) => {
|
||||
setCollaborators(res);
|
||||
setSelectedEmployeeId(""); // reset employee filter when org changes
|
||||
}).catch(console.error);
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
}, [selectedOrgId, sessionUser]);
|
||||
|
||||
@@ -43,14 +54,17 @@ export default function FinancialWidget({ sessionUser, selectedOrgId, organizati
|
||||
sessionUser,
|
||||
companyId: selectedOrgId,
|
||||
timeframe: selectedTimeframe,
|
||||
employeeId: selectedEmployeeId || undefined
|
||||
}).then((res) => {
|
||||
employeeId: selectedEmployeeId || undefined,
|
||||
})
|
||||
.then((res) => {
|
||||
setFinancials(res);
|
||||
}).catch((err) => {
|
||||
})
|
||||
.catch((err) => {
|
||||
const errMsg = err.format ? err.format() : err.message;
|
||||
console.warn("Acceso denegado a métricas financieras: ", errMsg);
|
||||
setError("No tienes permisos de administrador para esta organización.");
|
||||
}).finally(() => setLoading(false));
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
}
|
||||
}, [selectedOrgId, selectedTimeframe, selectedEmployeeId, sessionUser]);
|
||||
|
||||
@@ -64,15 +78,22 @@ export default function FinancialWidget({ sessionUser, selectedOrgId, organizati
|
||||
const previous = financials.previousPeriodTotal;
|
||||
|
||||
if (previous === 0) {
|
||||
if (current > 0) return <span className={styles.positive}>+100% vs periodo anterior</span>;
|
||||
if (current > 0)
|
||||
return <span className={styles.positive}>+100% vs periodo anterior</span>;
|
||||
return <span className={styles.neutral}>Sin datos previos</span>;
|
||||
}
|
||||
|
||||
const diff = current - previous;
|
||||
const percent = (diff / previous) * 100;
|
||||
|
||||
if (percent > 0) return <span className={styles.positive}>+{percent.toFixed(1)}% vs periodo anterior</span>;
|
||||
if (percent < 0) return <span className={styles.negative}>{percent.toFixed(1)}% vs periodo anterior</span>;
|
||||
if (percent > 0)
|
||||
return (
|
||||
<span className={styles.positive}>+{percent.toFixed(1)}% vs periodo anterior</span>
|
||||
);
|
||||
if (percent < 0)
|
||||
return (
|
||||
<span className={styles.negative}>{percent.toFixed(1)}% vs periodo anterior</span>
|
||||
);
|
||||
return <span className={styles.neutral}>0% vs periodo anterior</span>;
|
||||
};
|
||||
|
||||
@@ -81,15 +102,46 @@ export default function FinancialWidget({ sessionUser, selectedOrgId, organizati
|
||||
if (error) {
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<button className={styles.headerButton} type="button" onClick={() => setIsOpen((value) => !value)}>
|
||||
<button
|
||||
className={styles.headerButton}
|
||||
type="button"
|
||||
onClick={() => setIsOpen((value) => !value)}
|
||||
>
|
||||
<h3 className={styles.title}>
|
||||
Rendimiento Financiero {organizationName ? `- ${organizationName}` : ''}
|
||||
Rendimiento Financiero {organizationName ? `- ${organizationName}` : ""}
|
||||
</h3>
|
||||
<div style={{ display: "flex", alignItems: "center", gap: "8px" }}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => goTo(`/landing/org/${selectedOrgId}`)}
|
||||
style={{
|
||||
display: "inline-flex",
|
||||
alignItems: "center",
|
||||
gap: "6px",
|
||||
padding: "6px 12px",
|
||||
borderRadius: "999px",
|
||||
color: "var(--green-darkestX1)",
|
||||
border: "1px solid var(--green-darkestX1)",
|
||||
background: "var(--white)",
|
||||
textDecoration: "none",
|
||||
fontSize: "14px",
|
||||
fontWeight: 600,
|
||||
cursor: "pointer",
|
||||
transition: "all 0.2s ease",
|
||||
}}
|
||||
title="Ver perfil público de la organización"
|
||||
>
|
||||
<OpenInNewOutlinedIcon fontSize="small" />
|
||||
Ver perfil
|
||||
</button>
|
||||
<span className={styles.toggleIcon}>{isOpen ? "−" : "+"}</span>
|
||||
</div>
|
||||
</button>
|
||||
{isOpen && (
|
||||
<div style={{ padding: '40px 20px', textAlign: 'center', color: '#6b7280' }}>
|
||||
<p style={{ fontWeight: '600', marginBottom: '8px', color: '#374151' }}>Acceso Restringido</p>
|
||||
<div style={{ padding: "40px 20px", textAlign: "center", color: "#6b7280" }}>
|
||||
<p style={{ fontWeight: "600", marginBottom: "8px", color: "#374151" }}>
|
||||
Acceso Restringido
|
||||
</p>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
)}
|
||||
@@ -98,21 +150,50 @@ export default function FinancialWidget({ sessionUser, selectedOrgId, organizati
|
||||
}
|
||||
|
||||
const chartData = financials?.currentPeriodData || [];
|
||||
const xAxisData = chartData.map(d => {
|
||||
const xAxisData = chartData.map((d) => {
|
||||
// format label nicer depending on timeframe
|
||||
if (selectedTimeframe === "year") return dayjs(d.date).format("MMM YYYY");
|
||||
return dayjs(d.date).format("DD/MM");
|
||||
});
|
||||
const seriesData = chartData.map(d => d.amount);
|
||||
const hasChartData = chartData.some(d => d.amount > 0);
|
||||
const seriesData = chartData.map((d) => d.amount);
|
||||
const hasChartData = chartData.some((d) => d.amount > 0);
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<button className={styles.headerButton} type="button" onClick={() => setIsOpen((value) => !value)}>
|
||||
<button
|
||||
className={styles.headerButton}
|
||||
type="button"
|
||||
onClick={() => setIsOpen((value) => !value)}
|
||||
>
|
||||
<h3 className={styles.title}>
|
||||
Rendimiento Financiero {organizationName ? `- ${organizationName}` : ''}
|
||||
Rendimiento Financiero {organizationName ? `- ${organizationName}` : ""}
|
||||
</h3>
|
||||
<div style={{ display: "flex", alignItems: "center", gap: "8px" }}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => goTo(`/landing/org/${selectedOrgId}`)}
|
||||
style={{
|
||||
display: "inline-flex",
|
||||
alignItems: "center",
|
||||
gap: "6px",
|
||||
padding: "6px 12px",
|
||||
borderRadius: "999px",
|
||||
color: "var(--green-darkestX1)",
|
||||
border: "1px solid var(--green-darkestX1)",
|
||||
background: "var(--white)",
|
||||
textDecoration: "none",
|
||||
fontSize: "14px",
|
||||
fontWeight: 600,
|
||||
cursor: "pointer",
|
||||
transition: "all 0.2s ease",
|
||||
}}
|
||||
title="Ver perfil público de la organización"
|
||||
>
|
||||
<OpenInNewOutlinedIcon fontSize="small" />
|
||||
Ver perfil
|
||||
</button>
|
||||
<span className={styles.toggleIcon}>{isOpen ? "−" : "+"}</span>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
{isOpen && (
|
||||
@@ -121,7 +202,9 @@ export default function FinancialWidget({ sessionUser, selectedOrgId, organizati
|
||||
<select
|
||||
className={styles.select}
|
||||
value={selectedTimeframe}
|
||||
onChange={e => setSelectedTimeframe(e.target.value as "week" | "month" | "year")}
|
||||
onChange={(e) =>
|
||||
setSelectedTimeframe(e.target.value as "week" | "month" | "year")
|
||||
}
|
||||
>
|
||||
<option value="week">Última Semana</option>
|
||||
<option value="month">Último Mes</option>
|
||||
@@ -131,11 +214,13 @@ export default function FinancialWidget({ sessionUser, selectedOrgId, organizati
|
||||
<select
|
||||
className={styles.select}
|
||||
value={selectedEmployeeId}
|
||||
onChange={e => setSelectedEmployeeId(e.target.value)}
|
||||
onChange={(e) => setSelectedEmployeeId(e.target.value)}
|
||||
>
|
||||
<option value="">Todos los Profesionales</option>
|
||||
{collaborators.map(c => (
|
||||
<option key={c.id} value={c.id}>{c.fullName}</option>
|
||||
{collaborators.map((c) => (
|
||||
<option key={c.id} value={c.id}>
|
||||
{c.fullName}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
@@ -144,21 +229,29 @@ export default function FinancialWidget({ sessionUser, selectedOrgId, organizati
|
||||
<div className={styles.metricBox}>
|
||||
<span className={styles.metricLabel}>Ingresos del Periodo</span>
|
||||
<span className={styles.metricValue}>
|
||||
{loading ? "..." : formatCurrency(financials?.currentPeriodTotal || 0)}
|
||||
{loading
|
||||
? "..."
|
||||
: formatCurrency(financials?.currentPeriodTotal || 0)}
|
||||
</span>
|
||||
<div className={styles.metricComparison}>
|
||||
{!loading && renderComparison()}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{financials && (
|
||||
<UnpaidIncomeCard value={financials.unpaidToday} />
|
||||
)}
|
||||
{financials && <UnpaidIncomeCard value={financials.unpaidToday} />}
|
||||
</div>
|
||||
|
||||
{loading && (
|
||||
<div className={styles.chartContainer}>
|
||||
<div style={{display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100%', color: '#9ca3af'}}>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
height: "100%",
|
||||
color: "#9ca3af",
|
||||
}}
|
||||
>
|
||||
Cargando datos...
|
||||
</div>
|
||||
</div>
|
||||
@@ -168,57 +261,68 @@ export default function FinancialWidget({ sessionUser, selectedOrgId, organizati
|
||||
<div className={styles.chartContainer}>
|
||||
<LineChart
|
||||
height={350}
|
||||
xAxis={[{
|
||||
scaleType: 'point',
|
||||
xAxis={[
|
||||
{
|
||||
scaleType: "point",
|
||||
data: xAxisData,
|
||||
}]}
|
||||
},
|
||||
]}
|
||||
series={[
|
||||
{
|
||||
data: seriesData,
|
||||
color: 'rgb(36, 169, 53)',
|
||||
color: "rgb(36, 169, 53)",
|
||||
area: true,
|
||||
showMark: true,
|
||||
curve: 'monotoneX',
|
||||
valueFormatter: (val: number | null) => val ? formatCurrency(val) : "0",
|
||||
curve: "monotoneX",
|
||||
valueFormatter: (val: number | null) =>
|
||||
val ? formatCurrency(val) : "0",
|
||||
},
|
||||
]}
|
||||
grid={{ horizontal: true }}
|
||||
margin={{ top: 20, bottom: 40, left: 70, right: 20 }}
|
||||
sx={{
|
||||
'.MuiLineElement-root': {
|
||||
".MuiLineElement-root": {
|
||||
strokeWidth: 3,
|
||||
},
|
||||
'.MuiAreaElement-root': {
|
||||
fill: 'url(#gradient)',
|
||||
".MuiAreaElement-root": {
|
||||
fill: "url(#gradient)",
|
||||
},
|
||||
'.MuiChartsGrid-line': {
|
||||
strokeDasharray: '5 5',
|
||||
stroke: '#e5e7eb',
|
||||
".MuiChartsGrid-line": {
|
||||
strokeDasharray: "5 5",
|
||||
stroke: "#e5e7eb",
|
||||
},
|
||||
'.MuiChartsAxis-line': {
|
||||
stroke: 'transparent',
|
||||
".MuiChartsAxis-line": {
|
||||
stroke: "transparent",
|
||||
},
|
||||
'.MuiChartsAxis-tick': {
|
||||
stroke: 'transparent',
|
||||
".MuiChartsAxis-tick": {
|
||||
stroke: "transparent",
|
||||
},
|
||||
'.MuiChartsAxis-tickLabel': {
|
||||
fill: '#9ca3af',
|
||||
fontFamily: 'inherit',
|
||||
fontSize: '12px',
|
||||
".MuiChartsAxis-tickLabel": {
|
||||
fill: "#9ca3af",
|
||||
fontFamily: "inherit",
|
||||
fontSize: "12px",
|
||||
fontWeight: 500,
|
||||
},
|
||||
'.MuiMarkElement-root': {
|
||||
stroke: 'rgb(36, 169, 53)',
|
||||
".MuiMarkElement-root": {
|
||||
stroke: "rgb(36, 169, 53)",
|
||||
strokeWidth: 2,
|
||||
fill: '#ffffff',
|
||||
scale: '1.2',
|
||||
}
|
||||
fill: "#ffffff",
|
||||
scale: "1.2",
|
||||
},
|
||||
}}
|
||||
>
|
||||
<defs>
|
||||
<linearGradient id="gradient" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="5%" stopColor="rgb(36, 169, 53)" stopOpacity={0.3}/>
|
||||
<stop offset="95%" stopColor="rgb(36, 169, 53)" stopOpacity={0.0}/>
|
||||
<stop
|
||||
offset="5%"
|
||||
stopColor="rgb(36, 169, 53)"
|
||||
stopOpacity={0.3}
|
||||
/>
|
||||
<stop
|
||||
offset="95%"
|
||||
stopColor="rgb(36, 169, 53)"
|
||||
stopOpacity={0.0}
|
||||
/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</LineChart>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
right: 0px;
|
||||
height: 70px;
|
||||
overflow: hidden;
|
||||
z-index: 1;
|
||||
z-index: 100;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import classNames from "classnames";
|
||||
import { useNavigation } from "@core/app/hooks/goto";
|
||||
|
||||
import ShareOutlinedIcon from "@mui/icons-material/ShareOutlined";
|
||||
import OpenInNewIcon from "@mui/icons-material/OpenInNew";
|
||||
import Dialog from "@mui/material/Dialog";
|
||||
import DialogContent from "@mui/material/DialogContent";
|
||||
import DialogTitle from "@mui/material/DialogTitle";
|
||||
@@ -69,6 +70,14 @@ export default function OrganizationHeader(props: OrganizationHeaderParams): Rea
|
||||
icon: <ShareOutlinedIcon />,
|
||||
});
|
||||
|
||||
menu.add({
|
||||
text: "Ver perfil",
|
||||
onClick: () => {
|
||||
goTo(`/landing/org/${props.data.id}`);
|
||||
},
|
||||
icon: <OpenInNewIcon />,
|
||||
});
|
||||
|
||||
menu.add({
|
||||
text: "Notificaciones",
|
||||
onClick: () => {
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
"use client";
|
||||
import { useState, useEffect } from "react";
|
||||
import { Grid2, IconButton, Dialog, DialogActions, DialogContent, DialogTitle } from "@mui/material";
|
||||
import CloseIcon from "@mui/icons-material/Close";
|
||||
import turnosXpressTheme from "@core/app/theme/turnosXpress";
|
||||
import Button from "@mui/material/Button";
|
||||
import { ThemeProvider } from "@emotion/react";
|
||||
import { PopoverPicker } from "@components/ColorPicker/ColorPicker";
|
||||
import ImagePicker from "@components/ImagePicker/ImagePicker";
|
||||
import { useAlert } from "@core/Store/Alert.Store";
|
||||
import { useSessionStore } from "@core/Store/Sesion.Store";
|
||||
import { useOrganizationHeaderStore } from "@core/Store/OrganizationHeader.Store";
|
||||
import { updateOrganizationColors, uploadHeaderImage } from "@services/Header.Edit.Service";
|
||||
import { UpdateCompanyParams } from "@models/Company.model";
|
||||
|
||||
interface HeaderEditPopupProps {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
companyId: string;
|
||||
headerColor: string;
|
||||
headerFontColor: string;
|
||||
headerFontShadowColor: string;
|
||||
headerImage: string;
|
||||
onSaved: () => void;
|
||||
onRefresh?: () => void;
|
||||
}
|
||||
|
||||
export default function HeaderEditPopup(props: HeaderEditPopupProps) {
|
||||
const { open, onClose, companyId, headerColor, headerFontColor, headerFontShadowColor, headerImage, onSaved, onRefresh } = props;
|
||||
const alert = useAlert();
|
||||
const SessionInfo = useSessionStore();
|
||||
const organizationHeader = useOrganizationHeaderStore();
|
||||
|
||||
const [headerColorState, setHeaderColorState] = useState("");
|
||||
const [headerFontColorState, setHeaderFontColorState] = useState("");
|
||||
const [headerFontShadowColorState, setHeaderFontShadowColorState] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
// Sync local state when values change externally
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setHeaderColorState(headerColor || "");
|
||||
setHeaderFontColorState(headerFontColor || "");
|
||||
setHeaderFontShadowColorState(headerFontShadowColor || "");
|
||||
setLoading(false);
|
||||
}
|
||||
}, [open, headerColor, headerFontColor, headerFontShadowColor]);
|
||||
|
||||
const handleSaveColors = async () => {
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
const updData: UpdateCompanyParams = {
|
||||
id: companyId,
|
||||
headerColor: headerColorState,
|
||||
headerFontColor: headerFontColorState,
|
||||
headerFontShadowColor: headerFontShadowColorState,
|
||||
sessionUser: SessionInfo.userId,
|
||||
};
|
||||
|
||||
await updateOrganizationColors(updData);
|
||||
|
||||
organizationHeader.setHeaderColor(headerColorState);
|
||||
organizationHeader.setHeaderFontColor(headerFontColorState);
|
||||
organizationHeader.setHeaderFontShadowColor(headerFontShadowColorState);
|
||||
|
||||
alert.showSuccess("Colores actualizados");
|
||||
onSaved();
|
||||
onRefresh?.();
|
||||
} catch (error) {
|
||||
const formatted = error instanceof Error ? error.message : "Error al guardar los colores";
|
||||
alert.showError(formatted || "Error al guardar los colores");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleImageChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append("companyId", companyId);
|
||||
formData.append("sessionUser", SessionInfo.userId);
|
||||
formData.append("file", file);
|
||||
|
||||
uploadHeaderImage(formData).then(() => {
|
||||
alert.showSuccess("Imagen actualizada");
|
||||
onSaved();
|
||||
onRefresh?.();
|
||||
}).catch((error) => {
|
||||
const formatted = error instanceof Error ? error.message : "Error al guardar la imagen";
|
||||
alert.showError(formatted || "Error al guardar la imagen");
|
||||
}).finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
} catch (error) {
|
||||
const formatted = error instanceof Error ? error.message : "Error al guardar la imagen";
|
||||
alert.showError(formatted || "Error al guardar la imagen");
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ThemeProvider theme={turnosXpressTheme}>
|
||||
<Dialog
|
||||
open={open}
|
||||
onClose={onClose}
|
||||
maxWidth="sm"
|
||||
fullWidth
|
||||
PaperProps={{
|
||||
sx: {
|
||||
borderRadius: 2,
|
||||
height: 500,
|
||||
},
|
||||
}}
|
||||
>
|
||||
<DialogTitle sx={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
|
||||
Personalizar
|
||||
<IconButton onClick={onClose} size="small">
|
||||
<CloseIcon />
|
||||
</IconButton>
|
||||
</DialogTitle>
|
||||
|
||||
<DialogContent dividers sx={{ p: 3 }}>
|
||||
{/* Colores */}
|
||||
<Grid2 container spacing={1} mb={3}>
|
||||
<Grid2 size={4}>
|
||||
<PopoverPicker
|
||||
placeholder="Fondo"
|
||||
color={headerColorState}
|
||||
onChange={(color: string) => {
|
||||
setHeaderColorState(color);
|
||||
}}
|
||||
/>
|
||||
</Grid2>
|
||||
<Grid2 size={4}>
|
||||
<PopoverPicker
|
||||
placeholder="Fuente"
|
||||
color={headerFontColorState}
|
||||
onChange={(color: string) => {
|
||||
setHeaderFontColorState(color);
|
||||
}}
|
||||
/>
|
||||
</Grid2>
|
||||
<Grid2 size={4}>
|
||||
<PopoverPicker
|
||||
placeholder="Sombra"
|
||||
color={headerFontShadowColorState}
|
||||
onChange={(color: string) => {
|
||||
setHeaderFontShadowColorState(color);
|
||||
}}
|
||||
/>
|
||||
</Grid2>
|
||||
</Grid2>
|
||||
|
||||
{/* Imagen */}
|
||||
<ImagePicker
|
||||
src={headerImage}
|
||||
alt="Cabecera"
|
||||
style={{ width: "100%", height: 120, borderRadius: 8 }}
|
||||
readOnly={false}
|
||||
onChange={handleImageChange}
|
||||
imageSizeSrc="/org-header-size.webp"
|
||||
mbLimit={5}
|
||||
/>
|
||||
</DialogContent>
|
||||
|
||||
<DialogActions sx={{ px: 3, pb: 2 }}>
|
||||
<Button onClick={onClose}>Cancelar</Button>
|
||||
<Button
|
||||
onClick={handleSaveColors}
|
||||
autoFocus
|
||||
color="success"
|
||||
variant="contained"
|
||||
disabled={loading}
|
||||
>
|
||||
Guardar
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
"use client";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import HeaderEditPopup from "./HeaderEditPopup";
|
||||
import { useSessionStore } from "@core/Store/Sesion.Store";
|
||||
import { checkOrgAdmin } from "@services/Header.Edit.Service";
|
||||
|
||||
interface OrganizationHeaderEditProps {
|
||||
companyId: string;
|
||||
headerColor?: string;
|
||||
headerFontColor?: string;
|
||||
headerFontShadowColor?: string;
|
||||
headerImage?: string;
|
||||
}
|
||||
|
||||
export default function OrganizationHeaderEdit({
|
||||
companyId,
|
||||
headerColor = "",
|
||||
headerFontColor = "",
|
||||
headerFontShadowColor = "",
|
||||
headerImage = "",
|
||||
}: OrganizationHeaderEditProps) {
|
||||
const router = useRouter();
|
||||
const SessionInfo = useSessionStore();
|
||||
const [isOrgAdmin, setIsOrgAdmin] = useState(false);
|
||||
const [showEditPopup, setShowEditPopup] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!SessionInfo.userId || !companyId) {
|
||||
setIsOrgAdmin(false);
|
||||
const existing = document.getElementById("edit-header-btn");
|
||||
if (existing) existing.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
let cancelled = false;
|
||||
|
||||
checkOrgAdmin(companyId, SessionInfo.userId)
|
||||
.then((isAdmin) => {
|
||||
if (cancelled) return;
|
||||
setIsOrgAdmin(isAdmin);
|
||||
|
||||
const wrapper = document.getElementById("header-wrapper");
|
||||
if (!wrapper) return;
|
||||
|
||||
if (isAdmin) {
|
||||
const existingBtn = document.getElementById("edit-header-btn");
|
||||
if (existingBtn) existingBtn.remove();
|
||||
|
||||
const btn = document.createElement("div");
|
||||
btn.id = "edit-header-btn";
|
||||
btn.innerHTML = `
|
||||
<button style="
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
right: 12px;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
background: rgba(0,0,0,0.45);
|
||||
color: white;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 100;
|
||||
transition: background 0.2s;
|
||||
" onmouseover="this.style.background='rgba(0,0,0,0.7)'" onmouseout="this.style.background='rgba(0,0,0,0.45)'">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34a.9959.9959 0 0 0-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/></svg>
|
||||
</button>
|
||||
`;
|
||||
btn.querySelector("button")!.addEventListener("click", () =>
|
||||
setShowEditPopup(true),
|
||||
);
|
||||
wrapper.appendChild(btn);
|
||||
} else {
|
||||
const existingBtn = document.getElementById("edit-header-btn");
|
||||
if (existingBtn) existingBtn.remove();
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
if (cancelled) return;
|
||||
setIsOrgAdmin(false);
|
||||
|
||||
const existingBtn = document.getElementById("edit-header-btn");
|
||||
if (existingBtn) existingBtn.remove();
|
||||
});
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
const existing = document.getElementById("edit-header-btn");
|
||||
if (existing) existing.remove();
|
||||
};
|
||||
}, [SessionInfo.userId, companyId]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{isOrgAdmin && (
|
||||
<HeaderEditPopup
|
||||
open={showEditPopup}
|
||||
onClose={() => setShowEditPopup(false)}
|
||||
companyId={companyId}
|
||||
headerColor={headerColor}
|
||||
headerFontColor={headerFontColor}
|
||||
headerFontShadowColor={headerFontShadowColor}
|
||||
headerImage={headerImage}
|
||||
onSaved={() => {
|
||||
setShowEditPopup(false);
|
||||
}}
|
||||
onRefresh={() => router.refresh()}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { PublicServiceView } from "@models/Service.model";
|
||||
import style from "./style.module.css";
|
||||
import { getServiceImage } from "@core/helpers/getServiceImage";
|
||||
import ServiceRatingSummary from "@components/ServiceRatingSummary/ServiceRatingSummary";
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
|
||||
export type FindResultsViewMode = "grid" | "card";
|
||||
|
||||
@@ -14,6 +15,8 @@ export interface ProductItemProps {
|
||||
width?: number | string;
|
||||
viewMode?: FindResultsViewMode;
|
||||
dragging?: boolean;
|
||||
isAdmin?: boolean;
|
||||
onImageEdit?: () => void;
|
||||
}
|
||||
|
||||
export default function ProductItem(props: ProductItemProps) {
|
||||
@@ -21,6 +24,8 @@ export default function ProductItem(props: ProductItemProps) {
|
||||
const { product } = props;
|
||||
const { viewMode = "card" } = props;
|
||||
const { dragging = false } = props;
|
||||
const { isAdmin = false } = props;
|
||||
const { onImageEdit } = props;
|
||||
const { goTo } = useNavigation();
|
||||
|
||||
return (
|
||||
@@ -38,7 +43,7 @@ export default function ProductItem(props: ProductItemProps) {
|
||||
textAlign: "center",
|
||||
padding: "10px",
|
||||
border: "solid 1px rgba(0, 0, 0, 0.1)",
|
||||
cursor: "pointer",
|
||||
cursor: isAdmin ? "default" : "pointer",
|
||||
position: "relative",
|
||||
}}
|
||||
onClick={() => {
|
||||
@@ -58,6 +63,11 @@ export default function ProductItem(props: ProductItemProps) {
|
||||
display: "block",
|
||||
}}
|
||||
/>
|
||||
{isAdmin && (
|
||||
<span className={style.adminEditButton} onClick={(e) => { e.stopPropagation(); onImageEdit?.(); }}>
|
||||
<EditIcon fontSize="small" />
|
||||
</span>
|
||||
)}
|
||||
<ServiceRatingSummary
|
||||
serviceId={product.id}
|
||||
variant="card"
|
||||
|
||||
@@ -8,6 +8,32 @@
|
||||
bottom: 8px;
|
||||
}
|
||||
|
||||
.adminEditButton {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.adminEditButton:hover {
|
||||
background: var(--wine-red);
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.adminEditButton:hover svg {
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.cardHeader {
|
||||
margin: 10px 0;
|
||||
text-align: center;
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
"use client";
|
||||
import { useState, useEffect } from "react";
|
||||
import { Grid2, IconButton, Dialog, DialogActions, DialogContent, DialogTitle } from "@mui/material";
|
||||
import CloseIcon from "@mui/icons-material/Close";
|
||||
import turnosXpressTheme from "@core/app/theme/turnosXpress";
|
||||
import Button from "@mui/material/Button";
|
||||
import { ThemeProvider } from "@emotion/react";
|
||||
import { PopoverPicker } from "@components/ColorPicker/ColorPicker";
|
||||
import ImagePicker from "@components/ImagePicker/ImagePicker";
|
||||
import { useAlert } from "@core/Store/Alert.Store";
|
||||
import { useSessionStore } from "@core/Store/Sesion.Store";
|
||||
import { useOrganizationHeaderStore } from "@core/Store/OrganizationHeader.Store";
|
||||
import { updateOrganizationColors, uploadHeaderImage } from "@services/Header.Edit.Service";
|
||||
import { UpdateCompanyParams } from "@models/Company.model";
|
||||
|
||||
interface HeaderEditPopupProps {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
companyId: string;
|
||||
headerColor: string;
|
||||
headerFontColor: string;
|
||||
headerFontShadowColor: string;
|
||||
headerImage: string;
|
||||
onSaved: () => void;
|
||||
onRefresh?: () => void;
|
||||
}
|
||||
|
||||
export default function HeaderEditPopup(props: HeaderEditPopupProps) {
|
||||
const { open, onClose, companyId, headerColor, headerFontColor, headerFontShadowColor, headerImage, onSaved, onRefresh } = props;
|
||||
const alert = useAlert();
|
||||
const SessionInfo = useSessionStore();
|
||||
const organizationHeader = useOrganizationHeaderStore();
|
||||
|
||||
const [headerColorState, setHeaderColorState] = useState("");
|
||||
const [headerFontColorState, setHeaderFontColorState] = useState("");
|
||||
const [headerFontShadowColorState, setHeaderFontShadowColorState] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
// Sync local state when values change externally
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setHeaderColorState(headerColor || "");
|
||||
setHeaderFontColorState(headerFontColor || "");
|
||||
setHeaderFontShadowColorState(headerFontShadowColor || "");
|
||||
setLoading(false);
|
||||
}
|
||||
}, [open, headerColor, headerFontColor, headerFontShadowColor]);
|
||||
|
||||
const handleSaveColors = async () => {
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
const updData: UpdateCompanyParams = {
|
||||
id: companyId,
|
||||
headerColor: headerColorState,
|
||||
headerFontColor: headerFontColorState,
|
||||
headerFontShadowColor: headerFontShadowColorState,
|
||||
sessionUser: SessionInfo.userId,
|
||||
};
|
||||
|
||||
await updateOrganizationColors(updData);
|
||||
|
||||
organizationHeader.setHeaderColor(headerColorState);
|
||||
organizationHeader.setHeaderFontColor(headerFontColorState);
|
||||
organizationHeader.setHeaderFontShadowColor(headerFontShadowColorState);
|
||||
|
||||
alert.showSuccess("Colores actualizados");
|
||||
onSaved();
|
||||
onRefresh?.();
|
||||
} catch (error) {
|
||||
const formatted = error instanceof Error ? error.message : "Error al guardar los colores";
|
||||
alert.showError(formatted || "Error al guardar los colores");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleImageChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append("companyId", companyId);
|
||||
formData.append("sessionUser", SessionInfo.userId);
|
||||
formData.append("file", file);
|
||||
|
||||
uploadHeaderImage(formData).then(() => {
|
||||
alert.showSuccess("Imagen actualizada");
|
||||
onSaved();
|
||||
onRefresh?.();
|
||||
}).catch((error) => {
|
||||
const formatted = error instanceof Error ? error.message : "Error al guardar la imagen";
|
||||
alert.showError(formatted || "Error al guardar la imagen");
|
||||
}).finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
} catch (error) {
|
||||
const formatted = error instanceof Error ? error.message : "Error al guardar la imagen";
|
||||
alert.showError(formatted || "Error al guardar la imagen");
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ThemeProvider theme={turnosXpressTheme}>
|
||||
<Dialog
|
||||
open={open}
|
||||
onClose={onClose}
|
||||
maxWidth="sm"
|
||||
fullWidth
|
||||
PaperProps={{
|
||||
sx: {
|
||||
borderRadius: 2,
|
||||
height: 500,
|
||||
},
|
||||
}}
|
||||
>
|
||||
<DialogTitle sx={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
|
||||
Personalizar
|
||||
<IconButton onClick={onClose} size="small">
|
||||
<CloseIcon />
|
||||
</IconButton>
|
||||
</DialogTitle>
|
||||
|
||||
<DialogContent dividers sx={{ p: 3 }}>
|
||||
{/* Colores */}
|
||||
<Grid2 container spacing={1} mb={3}>
|
||||
<Grid2 size={4}>
|
||||
<PopoverPicker
|
||||
placeholder="Fondo"
|
||||
color={headerColorState}
|
||||
onChange={(color: string) => {
|
||||
setHeaderColorState(color);
|
||||
}}
|
||||
/>
|
||||
</Grid2>
|
||||
<Grid2 size={4}>
|
||||
<PopoverPicker
|
||||
placeholder="Fuente"
|
||||
color={headerFontColorState}
|
||||
onChange={(color: string) => {
|
||||
setHeaderFontColorState(color);
|
||||
}}
|
||||
/>
|
||||
</Grid2>
|
||||
<Grid2 size={4}>
|
||||
<PopoverPicker
|
||||
placeholder="Sombra"
|
||||
color={headerFontShadowColorState}
|
||||
onChange={(color: string) => {
|
||||
setHeaderFontShadowColorState(color);
|
||||
}}
|
||||
/>
|
||||
</Grid2>
|
||||
</Grid2>
|
||||
|
||||
{/* Imagen */}
|
||||
<ImagePicker
|
||||
src={headerImage}
|
||||
alt="Cabecera"
|
||||
style={{ width: "100%", height: 120, borderRadius: 8 }}
|
||||
readOnly={false}
|
||||
onChange={handleImageChange}
|
||||
imageSizeSrc="/org-header-size.webp"
|
||||
mbLimit={5}
|
||||
/>
|
||||
</DialogContent>
|
||||
|
||||
<DialogActions sx={{ px: 3, pb: 2 }}>
|
||||
<Button onClick={onClose}>Cancelar</Button>
|
||||
<Button
|
||||
onClick={handleSaveColors}
|
||||
autoFocus
|
||||
color="success"
|
||||
variant="contained"
|
||||
disabled={loading}
|
||||
>
|
||||
Guardar
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import ApiRequest from "@services/Api.Service";
|
||||
import { UpdateCompanyParams } from "@models/Company.model";
|
||||
import { ApiVoidResult } from "@models/Api.VoidResult.type";
|
||||
|
||||
export const updateOrganizationsById = async (
|
||||
data: UpdateCompanyParams
|
||||
): Promise<ApiVoidResult> => {
|
||||
return ApiRequest.post<ApiVoidResult>("companies/update", data);
|
||||
};
|
||||
|
||||
export const uploadHeaderImage = async (data: FormData): Promise<ApiVoidResult> => {
|
||||
return ApiRequest.postFile<ApiVoidResult>("companies/upload-header", data);
|
||||
};
|
||||
@@ -45,7 +45,9 @@ export default async function OrganizationPublicProfile({ params, children }: Pr
|
||||
<div className="homeCentered">
|
||||
{orgData.id && (
|
||||
<>
|
||||
<div style={{ position: "relative" }} id="header-wrapper">
|
||||
<OrganizationHeader organization={orgData} />
|
||||
</div>
|
||||
<OrganizationDataConnector orgData={orgData} />
|
||||
<div>{children}</div>
|
||||
</>
|
||||
|
||||
@@ -43,7 +43,10 @@ import { useSessionStore } from "@core/Store/Sesion.Store";
|
||||
import { EVENT_TYPES, useEventHandlerStore } from "@core/Store/EventHandler.Store";
|
||||
import { useAlert } from "@core/Store/Alert.Store";
|
||||
import { IPost } from "@core/Models/Posts.model";
|
||||
import { preprocessQuillHtml, transformQuillContentForDisplay } from "@core/app/helpers/htmlSainitize";
|
||||
import {
|
||||
preprocessQuillHtml,
|
||||
transformQuillContentForDisplay,
|
||||
} from "@core/app/helpers/htmlSainitize";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
|
||||
import { ThemeProvider } from "@emotion/react";
|
||||
@@ -55,12 +58,14 @@ import DownIcon from "@mui/icons-material/ArrowDownwardRounded";
|
||||
import PinIcon from "@mui/icons-material/PushPin";
|
||||
import EditIcon from "@mui/icons-material/AutoFixHigh";
|
||||
import turnosXpressTheme from "@core/app/theme/turnosXpress";
|
||||
import { useParams } from "next/navigation";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import dayjs from "dayjs";
|
||||
import { useConfirmStore } from "@core/Store/Confirm.Store";
|
||||
import ReviewsCarousel from "@core/app/components/ReviewsCarousel/ReviewsCarousel";
|
||||
import OrganizationProfessionals from "@core/app/components/OrganizationProfessionals/OrganizationProfessionals";
|
||||
import { RatingTargetType } from "@core/Models/Ratings.model";
|
||||
import HeaderEditPopup from "./HeaderEditPopup";
|
||||
import { checkOrgAdmin } from "./post.service";
|
||||
|
||||
enum VIEW {
|
||||
POSTS = "posts",
|
||||
@@ -76,6 +81,7 @@ type UrlData = {
|
||||
export default function OrganizationPublicProfile() {
|
||||
const data = useParams<UrlData>();
|
||||
const oid = data.oid;
|
||||
const router = useRouter();
|
||||
const OrganizationData = useOrgDataStore();
|
||||
const [position, setPosition] = useState<[number, number]>([0, 0]);
|
||||
const [orgData, setOrgData] = useState<PublicOrganizationView>();
|
||||
@@ -96,8 +102,85 @@ export default function OrganizationPublicProfile() {
|
||||
const [posts, setPosts] = useState<IPost[]>([]);
|
||||
const [authorizedUsers, setAuthorizedUsers] = useState<string[]>([]);
|
||||
const [currentPage, setCurrentPage] = useState<number>(1);
|
||||
|
||||
const [isOrgAdmin, setIsOrgAdmin] = useState<boolean>(false);
|
||||
const [showEditPopup, setShowEditPopup] = useState<boolean>(false);
|
||||
const SessionInfo = useSessionStore();
|
||||
|
||||
// Unified effect: check admin status and manage edit button DOM element
|
||||
useEffect(() => {
|
||||
if (!SessionInfo.userId || !oid) {
|
||||
setIsOrgAdmin(false);
|
||||
const existing = document.getElementById("edit-header-btn");
|
||||
if (existing) existing.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
let cancelled = false;
|
||||
|
||||
checkOrgAdmin(oid, SessionInfo.userId)
|
||||
.then((isAdmin) => {
|
||||
if (cancelled) return;
|
||||
console.log("isAdmin:", isAdmin);
|
||||
setIsOrgAdmin(isAdmin);
|
||||
|
||||
// Append or remove button based on the result
|
||||
const wrapper = document.getElementById("header-wrapper");
|
||||
if (!wrapper) return;
|
||||
|
||||
if (isAdmin) {
|
||||
const existingBtn = document.getElementById("edit-header-btn");
|
||||
if (existingBtn) existingBtn.remove();
|
||||
|
||||
const btn = document.createElement("div");
|
||||
btn.id = "edit-header-btn";
|
||||
btn.innerHTML = `
|
||||
<button style="
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
right: 12px;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
background: rgba(0,0,0,0.45);
|
||||
color: white;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 100;
|
||||
transition: background 0.2s;
|
||||
" onmouseover="this.style.background='rgba(0,0,0,0.7)'" onmouseout="this.style.background='rgba(0,0,0,0.45)'">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34a.9959.9959 0 0 0-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/></svg>
|
||||
</button>
|
||||
`;
|
||||
btn.querySelector("button")!.addEventListener("click", () =>
|
||||
setShowEditPopup(true),
|
||||
);
|
||||
wrapper.appendChild(btn);
|
||||
} else {
|
||||
// Remove button for non-admin users
|
||||
const existingBtn = document.getElementById("edit-header-btn");
|
||||
if (existingBtn) existingBtn.remove();
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
if (cancelled) return;
|
||||
setIsOrgAdmin(false);
|
||||
|
||||
// Ensure button is removed on error
|
||||
const existingBtn = document.getElementById("edit-header-btn");
|
||||
if (existingBtn) existingBtn.remove();
|
||||
});
|
||||
|
||||
// Cleanup: mark as cancelled and remove button
|
||||
return () => {
|
||||
cancelled = true;
|
||||
const existing = document.getElementById("edit-header-btn");
|
||||
if (existing) existing.remove();
|
||||
};
|
||||
}, [SessionInfo.userId, oid]);
|
||||
|
||||
const eventHandler = useEventHandlerStore();
|
||||
const alert = useAlert();
|
||||
const confirm = useConfirmStore();
|
||||
@@ -338,7 +421,8 @@ export default function OrganizationPublicProfile() {
|
||||
return response.data;
|
||||
}
|
||||
const newPosts = response.data.filter(
|
||||
(newPost) => !prevPosts.some((prevPost) => prevPost._id === newPost._id),
|
||||
(newPost) =>
|
||||
!prevPosts.some((prevPost) => prevPost._id === newPost._id),
|
||||
);
|
||||
|
||||
return [...prevPosts, ...newPosts];
|
||||
@@ -508,7 +592,11 @@ export default function OrganizationPublicProfile() {
|
||||
gap: "10px",
|
||||
}}
|
||||
>
|
||||
<WhatsappShareButton title={shareTitle} separator=":: " url={window.location.href}>
|
||||
<WhatsappShareButton
|
||||
title={shareTitle}
|
||||
separator=":: "
|
||||
url={window.location.href}
|
||||
>
|
||||
<WhatsAppShareIcon size={32} round />
|
||||
</WhatsappShareButton>
|
||||
<FacebookShareButton title={shareTitle} url={window.location.href}>
|
||||
@@ -531,6 +619,21 @@ export default function OrganizationPublicProfile() {
|
||||
return (
|
||||
<>
|
||||
<HeaderConfProvider />
|
||||
{isOrgAdmin && oid && orgData && (
|
||||
<HeaderEditPopup
|
||||
open={showEditPopup}
|
||||
onClose={() => setShowEditPopup(false)}
|
||||
companyId={oid}
|
||||
headerColor={orgData.headerColor}
|
||||
headerFontColor={orgData.headerFontColor}
|
||||
headerFontShadowColor={orgData.headerFontShadowColor}
|
||||
headerImage={orgData.headerFile}
|
||||
onSaved={() => {
|
||||
setShowEditPopup(false);
|
||||
}}
|
||||
onRefresh={() => router.refresh()}
|
||||
/>
|
||||
)}
|
||||
{orgData && (
|
||||
<div className={style.organizationContent}>
|
||||
{showEditor && (
|
||||
@@ -656,7 +759,9 @@ export default function OrganizationPublicProfile() {
|
||||
)}
|
||||
</div>
|
||||
{view === VIEW.SERVICES && (
|
||||
<div style={{ display: "flex", justifyContent: "flex-end" }}>
|
||||
<div
|
||||
style={{ display: "flex", justifyContent: "flex-end" }}
|
||||
>
|
||||
<ButtonGroup
|
||||
variant="outlined"
|
||||
aria-label="Basic button group"
|
||||
@@ -711,7 +816,8 @@ export default function OrganizationPublicProfile() {
|
||||
<div
|
||||
style={{
|
||||
textAlign: "center",
|
||||
backgroundImage: "url(/no-conversation.webp)",
|
||||
backgroundImage:
|
||||
"url(/no-conversation.webp)",
|
||||
backgroundRepeat: "no-repeat",
|
||||
backgroundPosition: "center center",
|
||||
backgroundSize: "50% auto",
|
||||
@@ -726,7 +832,8 @@ export default function OrganizationPublicProfile() {
|
||||
<div
|
||||
key={post._id}
|
||||
style={{
|
||||
borderBottom: "1px solid var(--gray-light)",
|
||||
borderBottom:
|
||||
"1px solid var(--gray-light)",
|
||||
paddingTop: "5px",
|
||||
paddingBottom: "10px",
|
||||
paddingLeft: "30px",
|
||||
@@ -740,7 +847,11 @@ export default function OrganizationPublicProfile() {
|
||||
justifyContent: "space-between",
|
||||
}}
|
||||
>
|
||||
<div style={{ color: "var(--gray-darkest)" }}>
|
||||
<div
|
||||
style={{
|
||||
color: "var(--gray-darkest)",
|
||||
}}
|
||||
>
|
||||
{dayjs(post.createdAt).format(
|
||||
"DD MMMM YYYY HH:mm",
|
||||
)}
|
||||
@@ -780,22 +891,30 @@ export default function OrganizationPublicProfile() {
|
||||
color: "var(--gray-darkest)",
|
||||
}}
|
||||
>
|
||||
<ThemeProvider theme={turnosXpressTheme}>
|
||||
<ThemeProvider
|
||||
theme={turnosXpressTheme}
|
||||
>
|
||||
<MaterialButton
|
||||
color="inherit"
|
||||
startIcon={<ClipIcon />}
|
||||
onClick={() => {
|
||||
fijarPost(`${post._id}`);
|
||||
fijarPost(
|
||||
`${post._id}`,
|
||||
);
|
||||
}}
|
||||
>
|
||||
{post.fixed ? "Liberar" : "Fijar"}
|
||||
{post.fixed
|
||||
? "Liberar"
|
||||
: "Fijar"}
|
||||
</MaterialButton>
|
||||
|
||||
{post.fixed && (
|
||||
<>
|
||||
<MaterialButton
|
||||
color="inherit"
|
||||
startIcon={<UpIcon />}
|
||||
startIcon={
|
||||
<UpIcon />
|
||||
}
|
||||
onClick={() => {
|
||||
moverPost(
|
||||
`${post._id}`,
|
||||
@@ -808,7 +927,9 @@ export default function OrganizationPublicProfile() {
|
||||
|
||||
<MaterialButton
|
||||
color="inherit"
|
||||
startIcon={<DownIcon />}
|
||||
startIcon={
|
||||
<DownIcon />
|
||||
}
|
||||
onClick={() => {
|
||||
moverPost(
|
||||
`${post._id}`,
|
||||
@@ -824,7 +945,9 @@ export default function OrganizationPublicProfile() {
|
||||
<MaterialButton
|
||||
color="inherit"
|
||||
onClick={() => {
|
||||
editarPost(`${post._id}`);
|
||||
editarPost(
|
||||
`${post._id}`,
|
||||
);
|
||||
}}
|
||||
>
|
||||
<EditIcon />
|
||||
@@ -833,7 +956,9 @@ export default function OrganizationPublicProfile() {
|
||||
<MaterialButton
|
||||
color="inherit"
|
||||
onClick={() => {
|
||||
eliminarPost(`${post._id}`);
|
||||
eliminarPost(
|
||||
`${post._id}`,
|
||||
);
|
||||
}}
|
||||
>
|
||||
<DeleteIcon />
|
||||
@@ -858,7 +983,8 @@ export default function OrganizationPublicProfile() {
|
||||
style={{
|
||||
padding: "0px 0px 40px 0px",
|
||||
display: "flex",
|
||||
flexDirection: viewMode === "card" ? "row" : "column",
|
||||
flexDirection:
|
||||
viewMode === "card" ? "row" : "column",
|
||||
justifyContent: "start",
|
||||
gap: "20px",
|
||||
flexWrap: "wrap",
|
||||
|
||||
@@ -65,3 +65,7 @@ export const toggleFixedPost = async (data: FixCompanyPostParams): Promise<void>
|
||||
export const moveFixedPost = async (data: MoveCompanyFixedPostParams): Promise<void> => {
|
||||
return ApiRequest.post<void>("companies/move-fixed-post", data);
|
||||
};
|
||||
|
||||
export const checkOrgAdmin = async (companyId: string, sessionUser: string): Promise<boolean> => {
|
||||
return ApiRequest.post<boolean>("companies/check-admin", { companyId, sessionUser });
|
||||
};
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import ApiRequest from "@services/Api.Service";
|
||||
import { ApiVoidResult } from "@models/Api.VoidResult.type";
|
||||
|
||||
export const uploadServiceImage = async (data: FormData): Promise<ApiVoidResult> => {
|
||||
return ApiRequest.postFile<ApiVoidResult>("services/upload-image", data);
|
||||
};
|
||||
|
||||
export const checkOrgAdmin = async (companyId: string, sessionUser: string): Promise<boolean> => {
|
||||
return ApiRequest.post<boolean>("companies/check-admin", { companyId, sessionUser });
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
"use client";
|
||||
import { useState, useEffect } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import ProductItem from "@core/app/components/ProductItem/ProductItem";
|
||||
import { PublicServiceView } from "@models/Service.model";
|
||||
import { PublicOrganizationView } from "@models/Company.model";
|
||||
import ServiceImageEditPopup from "./ServiceImageEditPopup";
|
||||
import { useSessionStore } from "@core/Store/Sesion.Store";
|
||||
import { checkOrgAdmin } from "@services/Header.Edit.Service";
|
||||
|
||||
interface ServiceDetailCardProps {
|
||||
service: PublicServiceView;
|
||||
organization: PublicOrganizationView;
|
||||
}
|
||||
|
||||
export default function ServiceDetailCard({ service, organization }: ServiceDetailCardProps) {
|
||||
const router = useRouter();
|
||||
const SessionInfo = useSessionStore();
|
||||
const [isAdmin, setIsAdmin] = useState(false);
|
||||
const [showEditPopup, setShowEditPopup] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!SessionInfo.userId || !organization.id || !service.id) return;
|
||||
|
||||
checkOrgAdmin(organization.id, SessionInfo.userId)
|
||||
.then((result) => {
|
||||
setIsAdmin(result);
|
||||
})
|
||||
.catch(() => {
|
||||
setIsAdmin(false);
|
||||
});
|
||||
}, [SessionInfo.userId, organization.id, service.id]);
|
||||
|
||||
const handleImageSaved = () => {
|
||||
setShowEditPopup(false);
|
||||
router.refresh();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<ProductItem
|
||||
product={service}
|
||||
width="100%"
|
||||
isAdmin={isAdmin}
|
||||
onImageEdit={() => setShowEditPopup(true)}
|
||||
/>
|
||||
{isAdmin && (
|
||||
<ServiceImageEditPopup
|
||||
open={showEditPopup}
|
||||
onClose={() => setShowEditPopup(false)}
|
||||
serviceId={service.id}
|
||||
companyId={organization.id}
|
||||
currentImage={service.image}
|
||||
onSaved={handleImageSaved}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
"use client";
|
||||
import { useState } from "react";
|
||||
import { IconButton, Dialog, DialogActions, DialogContent, DialogTitle, Button } from "@mui/material";
|
||||
import CloseIcon from "@mui/icons-material/Close";
|
||||
import turnosXpressTheme from "@core/app/theme/turnosXpress";
|
||||
import { ThemeProvider } from "@emotion/react";
|
||||
import ImagePicker from "@components/ImagePicker/ImagePicker";
|
||||
import { useAlert } from "@core/Store/Alert.Store";
|
||||
import { useSessionStore } from "@core/Store/Sesion.Store";
|
||||
import { uploadServiceImage } from "@services/Header.Edit.Service";
|
||||
|
||||
interface ServiceImageEditPopupProps {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
serviceId: string;
|
||||
companyId: string;
|
||||
currentImage: string;
|
||||
onSaved: () => void;
|
||||
}
|
||||
|
||||
export default function ServiceImageEditPopup(props: ServiceImageEditPopupProps) {
|
||||
const { open, onClose, serviceId, companyId, currentImage, onSaved } = props;
|
||||
const alert = useAlert();
|
||||
const SessionInfo = useSessionStore();
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const handleImageChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append("companyId", companyId);
|
||||
formData.append("serviceId", serviceId);
|
||||
formData.append("sessionUser", SessionInfo.userId);
|
||||
formData.append("file", file);
|
||||
|
||||
uploadServiceImage(formData)
|
||||
.then(() => {
|
||||
alert.showSuccess("Imagen actualizada");
|
||||
onSaved();
|
||||
})
|
||||
.catch((error) => {
|
||||
const formatted = error instanceof Error ? error.message : "Error al guardar la imagen";
|
||||
alert.showError(formatted || "Error al guardar la imagen");
|
||||
})
|
||||
.finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
} catch (error) {
|
||||
const formatted = error instanceof Error ? error.message : "Error al guardar la imagen";
|
||||
alert.showError(formatted || "Error al guardar la imagen");
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ThemeProvider theme={turnosXpressTheme}>
|
||||
<Dialog
|
||||
open={open}
|
||||
onClose={onClose}
|
||||
maxWidth="sm"
|
||||
fullWidth
|
||||
PaperProps={{
|
||||
sx: {
|
||||
borderRadius: 2,
|
||||
width: 'auto',
|
||||
height: 'auto',
|
||||
},
|
||||
}}
|
||||
>
|
||||
<DialogTitle sx={{ display: "flex", justifyContent: "space-between", alignItems: "center", py: 2 }}>
|
||||
Editar imagen del servicio
|
||||
<IconButton onClick={onClose} size="small">
|
||||
<CloseIcon />
|
||||
</IconButton>
|
||||
</DialogTitle>
|
||||
|
||||
<DialogContent dividers sx={{ p: 3, display: "flex", justifyContent: "center" }}>
|
||||
<ImagePicker
|
||||
src={currentImage}
|
||||
alt="Imagen del servicio"
|
||||
style={{ width: 400, height: 400, borderRadius: 8 }}
|
||||
readOnly={false}
|
||||
onChange={handleImageChange}
|
||||
imageSizeSrc="/service-image-size.webp"
|
||||
mbLimit={5}
|
||||
/>
|
||||
</DialogContent>
|
||||
|
||||
<DialogActions sx={{ px: 3, pb: 2, pt: 1 }}>
|
||||
<Button onClick={onClose}>Cancelar</Button>
|
||||
<Button
|
||||
onClick={() => {}}
|
||||
disabled={loading}
|
||||
>
|
||||
Guardar
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import AnimatedContainer from "@components/AnimatedConainer/AnimatedContainer";
|
||||
import style from "./profile.module.css";
|
||||
import ApiServerService from "@services/Api.Server.Service";
|
||||
import { PublicOrganizationServiceView } from "@core/Models/Service.model";
|
||||
import ProductItem from "@core/app/components/ProductItem/ProductItem";
|
||||
import Appointment from "./components/Appointment/Appointment";
|
||||
import OrganizationHeader from "@components/Home/OrganizationHeader/OrganizationHeader";
|
||||
import ProductGallery from "@core/app/components/Home/ProductsGallery/ProductGallery";
|
||||
@@ -12,6 +11,8 @@ import ServicePrivate from "@core/app/components/ServicePrivate/ServicePrivate";
|
||||
import EvangelizeBanner from "@components/EvangelizeBanner/EvangelizeBanner";
|
||||
import ReviewsCarousel from "@components/ReviewsCarousel/ReviewsCarousel";
|
||||
import { RatingTargetType } from "@core/Models/Ratings.model";
|
||||
import ServiceDetailCard from "./ServiceDetailCard";
|
||||
import OrganizationHeaderEdit from "@components/OrganizationHeaderEdit/OrganizationHeaderEdit";
|
||||
|
||||
const GetServiceData = async (serviceId: string): Promise<PublicOrganizationServiceView> => {
|
||||
try {
|
||||
@@ -56,11 +57,20 @@ export default async function OrganizationPublicProfile({ params }: Props) {
|
||||
<ScrollToTop />
|
||||
<HeaderConfProvider />
|
||||
<div className="homeCentered">
|
||||
<div id="header-wrapper" style={{ position: "relative" }}>
|
||||
<OrganizationHeader organization={organizationService.organization} />
|
||||
</div>
|
||||
<OrganizationHeaderEdit
|
||||
companyId={organizationService.organization.id}
|
||||
headerColor={organizationService.organization.headerColor}
|
||||
headerFontColor={organizationService.organization.headerFontColor}
|
||||
headerFontShadowColor={organizationService.organization.headerFontShadowColor}
|
||||
headerImage={organizationService.organization.headerFile}
|
||||
/>
|
||||
<div className={style.organizationContent}>
|
||||
<div className={style.serviceSide}>
|
||||
<div className={style.stickyWrapper}>
|
||||
<ProductItem product={organizationService.service} width="100%" />
|
||||
<ServiceDetailCard service={organizationService.service} organization={organizationService.organization} />
|
||||
</div>
|
||||
</div>
|
||||
<div className={style.bookingSide}>
|
||||
|
||||
Reference in New Issue
Block a user