Compare commits
13 Commits
57c5deb3bd
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 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_ACCESS_TOKEN = APP_USR-8753424836448507-121412-731599daea1ffa0b278b5dcc78aa1ec8-1611134648
|
||||||
MP_BACK_URL = https://turnosxpress.com.ar/landing/dashboard
|
MP_BACK_URL = https://turnosxpress.com.ar/landing/dashboard
|
||||||
MP_CHECK_PAYMENT_MINUTES = 1
|
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
|
DEFAULT_BOT_ADMIN_PORT = 3005
|
||||||
|
|
||||||
|
|||||||
@@ -380,4 +380,5 @@ export interface ICompaniesManager {
|
|||||||
sysAdminUpdate(data: SysAdminUpdateCompanyParams): Promise<void>;
|
sysAdminUpdate(data: SysAdminUpdateCompanyParams): Promise<void>;
|
||||||
sysAdminSetBanned(data: SysAdminSetCompanyBannedParams): Promise<void>;
|
sysAdminSetBanned(data: SysAdminSetCompanyBannedParams): Promise<void>;
|
||||||
sysAdminGetInsights(data: SysAdminCompanyInsightsParams): Promise<SysAdminCompanyInsightsResult>;
|
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();
|
const CompaniesList = new CompaniesManager();
|
||||||
|
|||||||
@@ -112,7 +112,6 @@ export class PlanUsageCycleAdapterMongoose implements IPlanUsageCycleAdapter {
|
|||||||
planId: data.planId,
|
planId: data.planId,
|
||||||
cycleStart: data.cycleStart,
|
cycleStart: data.cycleStart,
|
||||||
cycleEnd: data.cycleEnd,
|
cycleEnd: data.cycleEnd,
|
||||||
appointmentsCount: 0,
|
|
||||||
creationDate: now,
|
creationDate: now,
|
||||||
},
|
},
|
||||||
$inc: { appointmentsCount: data.quantity },
|
$inc: { appointmentsCount: data.quantity },
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export class ToggleCompanyFixedPostController extends Controller {
|
|||||||
@SuccessResponse(200, "Done")
|
@SuccessResponse(200, "Done")
|
||||||
@Post()
|
@Post()
|
||||||
public async toggleFixedCompanyPost(
|
public async toggleFixedCompanyPost(
|
||||||
@Body() requestBody: FixCompanyPostParams
|
@Body() requestBody: FixCompanyPostParams,
|
||||||
): Promise<ApiVoidResult | ApiValidationError> {
|
): Promise<ApiVoidResult | ApiValidationError> {
|
||||||
try {
|
try {
|
||||||
await new CompaniesService().toggleFixedPost(requestBody);
|
await new CompaniesService().toggleFixedPost(requestBody);
|
||||||
@@ -62,7 +62,7 @@ export class MoveCompanyFixedPostController extends Controller {
|
|||||||
@SuccessResponse(200, "Done")
|
@SuccessResponse(200, "Done")
|
||||||
@Post()
|
@Post()
|
||||||
public async moveFixedCompanyPost(
|
public async moveFixedCompanyPost(
|
||||||
@Body() requestBody: MoveCompanyFixedPostParams
|
@Body() requestBody: MoveCompanyFixedPostParams,
|
||||||
): Promise<ApiVoidResult | ApiValidationError> {
|
): Promise<ApiVoidResult | ApiValidationError> {
|
||||||
try {
|
try {
|
||||||
await new CompaniesService().moveFixedPost(requestBody);
|
await new CompaniesService().moveFixedPost(requestBody);
|
||||||
@@ -86,7 +86,7 @@ export class SetNotificationsStatusCompanyController extends Controller {
|
|||||||
@SuccessResponse(200, "Done")
|
@SuccessResponse(200, "Done")
|
||||||
@Post()
|
@Post()
|
||||||
public async setNotificationAuto(
|
public async setNotificationAuto(
|
||||||
@Body() requestBody: SetNotificationAutoParams
|
@Body() requestBody: SetNotificationAutoParams,
|
||||||
): Promise<ApiVoidResult | ApiValidationError> {
|
): Promise<ApiVoidResult | ApiValidationError> {
|
||||||
try {
|
try {
|
||||||
await new CompaniesService().setNotificationAuto(requestBody);
|
await new CompaniesService().setNotificationAuto(requestBody);
|
||||||
@@ -110,7 +110,7 @@ export class SetPublishedStatusCompanyController extends Controller {
|
|||||||
@SuccessResponse(200, "Done")
|
@SuccessResponse(200, "Done")
|
||||||
@Post()
|
@Post()
|
||||||
public async setPublishedStatus(
|
public async setPublishedStatus(
|
||||||
@Body() requestBody: SetOrganizationPublishedStatusParams
|
@Body() requestBody: SetOrganizationPublishedStatusParams,
|
||||||
): Promise<ApiVoidResult | ApiValidationError> {
|
): Promise<ApiVoidResult | ApiValidationError> {
|
||||||
try {
|
try {
|
||||||
await new CompaniesService().setPublishedStatus(requestBody);
|
await new CompaniesService().setPublishedStatus(requestBody);
|
||||||
@@ -134,7 +134,7 @@ export class CreateCompanyController extends Controller {
|
|||||||
@SuccessResponse(200, "La compañia fue creada con exito")
|
@SuccessResponse(200, "La compañia fue creada con exito")
|
||||||
@Post()
|
@Post()
|
||||||
public async createCompany(
|
public async createCompany(
|
||||||
@Body() requestBody: CreateCompanyParams
|
@Body() requestBody: CreateCompanyParams,
|
||||||
): Promise<ICompany | ApiValidationError> {
|
): Promise<ICompany | ApiValidationError> {
|
||||||
try {
|
try {
|
||||||
const company = await new CompaniesService().createCompany(requestBody);
|
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")
|
@SuccessResponse(200, "La compañia fue modificada con exito")
|
||||||
@Post()
|
@Post()
|
||||||
public async deleteCompany(
|
public async deleteCompany(
|
||||||
@Body() requestBody: DeleteCompanyParams
|
@Body() requestBody: DeleteCompanyParams,
|
||||||
): Promise<ApiVoidResult | ApiValidationError> {
|
): Promise<ApiVoidResult | ApiValidationError> {
|
||||||
try {
|
try {
|
||||||
await new CompaniesService().deleteCompany(requestBody);
|
await new CompaniesService().deleteCompany(requestBody);
|
||||||
@@ -179,7 +179,7 @@ export class UpdateCompanyController extends Controller {
|
|||||||
@SuccessResponse(200, "La compañia fue modificada con exito")
|
@SuccessResponse(200, "La compañia fue modificada con exito")
|
||||||
@Post()
|
@Post()
|
||||||
public async updateCompany(
|
public async updateCompany(
|
||||||
@Body() requestBody: UpdateCompanyParams
|
@Body() requestBody: UpdateCompanyParams,
|
||||||
): Promise<ApiVoidResult | ApiValidationError> {
|
): Promise<ApiVoidResult | ApiValidationError> {
|
||||||
try {
|
try {
|
||||||
await new CompaniesService().updateCompany(requestBody);
|
await new CompaniesService().updateCompany(requestBody);
|
||||||
@@ -202,7 +202,7 @@ export class GetCompanyByIdController extends Controller {
|
|||||||
@SuccessResponse(200, "Done")
|
@SuccessResponse(200, "Done")
|
||||||
@Post()
|
@Post()
|
||||||
public async getById(
|
public async getById(
|
||||||
@Body() requestBody: OranizationsViewByIdParams
|
@Body() requestBody: OranizationsViewByIdParams,
|
||||||
): Promise<MyOranizationsView | ApiValidationError> {
|
): Promise<MyOranizationsView | ApiValidationError> {
|
||||||
try {
|
try {
|
||||||
const companies = await new CompaniesService().getById(requestBody);
|
const companies = await new CompaniesService().getById(requestBody);
|
||||||
@@ -222,7 +222,7 @@ export class GetCompanyByUserController extends Controller {
|
|||||||
@SuccessResponse(200, "Done")
|
@SuccessResponse(200, "Done")
|
||||||
@Post()
|
@Post()
|
||||||
public async getByUserId(
|
public async getByUserId(
|
||||||
@Body() requestBody: MyOranizationsViewParams
|
@Body() requestBody: MyOranizationsViewParams,
|
||||||
): Promise<MyOranizationsView[] | ApiValidationError> {
|
): Promise<MyOranizationsView[] | ApiValidationError> {
|
||||||
try {
|
try {
|
||||||
const companies = await new CompaniesService().getByUserId(requestBody);
|
const companies = await new CompaniesService().getByUserId(requestBody);
|
||||||
@@ -242,7 +242,7 @@ export class PaginateCompanyController extends Controller {
|
|||||||
@SuccessResponse(200, "Done")
|
@SuccessResponse(200, "Done")
|
||||||
@Post()
|
@Post()
|
||||||
public async paginateUsers(
|
public async paginateUsers(
|
||||||
@Body() requestBody: PaginateCompaniesParams
|
@Body() requestBody: PaginateCompaniesParams,
|
||||||
): Promise<PaginateCompaniesResults | ApiValidationError> {
|
): Promise<PaginateCompaniesResults | ApiValidationError> {
|
||||||
try {
|
try {
|
||||||
const users = await new CompaniesService().paginateCompanies(requestBody);
|
const users = await new CompaniesService().paginateCompanies(requestBody);
|
||||||
@@ -265,7 +265,7 @@ export class UploadCompanyHeaderController extends Controller {
|
|||||||
public async uploadHeader(
|
public async uploadHeader(
|
||||||
@FormField() companyId: string,
|
@FormField() companyId: string,
|
||||||
@FormField() sessionUser: string,
|
@FormField() sessionUser: string,
|
||||||
@UploadedFile() file: Express.Multer.File
|
@UploadedFile() file: Express.Multer.File,
|
||||||
): Promise<ApiVoidResult | ApiValidationError> {
|
): Promise<ApiVoidResult | ApiValidationError> {
|
||||||
try {
|
try {
|
||||||
await new CompaniesService().setCompanyHeader({
|
await new CompaniesService().setCompanyHeader({
|
||||||
@@ -295,7 +295,7 @@ export class UploadCompanyIconController extends Controller {
|
|||||||
public async uploadIcon(
|
public async uploadIcon(
|
||||||
@FormField() companyId: string,
|
@FormField() companyId: string,
|
||||||
@FormField() sessionUser: string,
|
@FormField() sessionUser: string,
|
||||||
@UploadedFile() file: Express.Multer.File
|
@UploadedFile() file: Express.Multer.File,
|
||||||
): Promise<ApiVoidResult | ApiValidationError> {
|
): Promise<ApiVoidResult | ApiValidationError> {
|
||||||
try {
|
try {
|
||||||
await new CompaniesService().setCompanyIcon({
|
await new CompaniesService().setCompanyIcon({
|
||||||
@@ -325,7 +325,7 @@ export class DeleteCompanyHeaderController extends Controller {
|
|||||||
@SuccessResponse(200, "El archivo fue cargado con exito")
|
@SuccessResponse(200, "El archivo fue cargado con exito")
|
||||||
@Post()
|
@Post()
|
||||||
public async deleteHeader(
|
public async deleteHeader(
|
||||||
@Body() data: DeleteCompanyFileParams
|
@Body() data: DeleteCompanyFileParams,
|
||||||
): Promise<ApiVoidResult | ApiValidationError> {
|
): Promise<ApiVoidResult | ApiValidationError> {
|
||||||
try {
|
try {
|
||||||
await new CompaniesService().deleteCompanyHeader(data);
|
await new CompaniesService().deleteCompanyHeader(data);
|
||||||
@@ -349,7 +349,7 @@ export class DeleteCompanyIconController extends Controller {
|
|||||||
@SuccessResponse(200, "El archivo fue cargado con exito")
|
@SuccessResponse(200, "El archivo fue cargado con exito")
|
||||||
@Post()
|
@Post()
|
||||||
public async deleteIcon(
|
public async deleteIcon(
|
||||||
@Body() data: DeleteCompanyFileParams
|
@Body() data: DeleteCompanyFileParams,
|
||||||
): Promise<ApiVoidResult | ApiValidationError> {
|
): Promise<ApiVoidResult | ApiValidationError> {
|
||||||
try {
|
try {
|
||||||
await new CompaniesService().deleteCompanyIcon(data);
|
await new CompaniesService().deleteCompanyIcon(data);
|
||||||
@@ -372,7 +372,7 @@ export class filterAllOrganizationsController extends Controller {
|
|||||||
@SuccessResponse(200, "Done")
|
@SuccessResponse(200, "Done")
|
||||||
@Post()
|
@Post()
|
||||||
public async filterAllOrganizations(
|
public async filterAllOrganizations(
|
||||||
@Body() requestBody: PaginateCompaniesParams
|
@Body() requestBody: PaginateCompaniesParams,
|
||||||
): Promise<TextObjectFilterResult[] | ApiValidationError> {
|
): Promise<TextObjectFilterResult[] | ApiValidationError> {
|
||||||
try {
|
try {
|
||||||
const clients = await new CompaniesService().filterAll(requestBody);
|
const clients = await new CompaniesService().filterAll(requestBody);
|
||||||
@@ -392,7 +392,7 @@ export class CheckCompanyNameController extends Controller {
|
|||||||
@SuccessResponse(200, "Done")
|
@SuccessResponse(200, "Done")
|
||||||
@Post()
|
@Post()
|
||||||
public async checkName(
|
public async checkName(
|
||||||
@Body() requestBody: { name: string }
|
@Body() requestBody: { name: string },
|
||||||
): Promise<{ valid: boolean } | ApiValidationError> {
|
): Promise<{ valid: boolean } | ApiValidationError> {
|
||||||
try {
|
try {
|
||||||
const valid = await new CompaniesService().checkNameExists(requestBody.name);
|
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 });
|
const isValid = await CompaniestList.isValidName({ name });
|
||||||
return isValid;
|
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."),
|
start: Yup.string().required("Debe seleccionar una fecha."),
|
||||||
price: Yup.number().positive().required("Debe introducir un precio valido."),
|
price: Yup.number().positive().required("Debe introducir un precio valido."),
|
||||||
length: Yup.number().positive().required("Debe introducir una duración."),
|
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."),
|
sessionUser: Yup.string().required("Para crear un turno debe iniciar sesión."),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+1
@@ -1,5 +1,6 @@
|
|||||||
.movementsPage {
|
.movementsPage {
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
|
padding-top: 200px;
|
||||||
padding-bottom: 32px;
|
padding-bottom: 32px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
right: 0px;
|
right: 0px;
|
||||||
height: 70px;
|
height: 70px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
z-index: 1;
|
z-index: 100;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 style from "./style.module.css";
|
||||||
import { getServiceImage } from "@core/helpers/getServiceImage";
|
import { getServiceImage } from "@core/helpers/getServiceImage";
|
||||||
import ServiceRatingSummary from "@components/ServiceRatingSummary/ServiceRatingSummary";
|
import ServiceRatingSummary from "@components/ServiceRatingSummary/ServiceRatingSummary";
|
||||||
|
import EditIcon from "@mui/icons-material/Edit";
|
||||||
|
|
||||||
export type FindResultsViewMode = "grid" | "card";
|
export type FindResultsViewMode = "grid" | "card";
|
||||||
|
|
||||||
@@ -14,6 +15,8 @@ export interface ProductItemProps {
|
|||||||
width?: number | string;
|
width?: number | string;
|
||||||
viewMode?: FindResultsViewMode;
|
viewMode?: FindResultsViewMode;
|
||||||
dragging?: boolean;
|
dragging?: boolean;
|
||||||
|
isAdmin?: boolean;
|
||||||
|
onImageEdit?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ProductItem(props: ProductItemProps) {
|
export default function ProductItem(props: ProductItemProps) {
|
||||||
@@ -21,6 +24,8 @@ export default function ProductItem(props: ProductItemProps) {
|
|||||||
const { product } = props;
|
const { product } = props;
|
||||||
const { viewMode = "card" } = props;
|
const { viewMode = "card" } = props;
|
||||||
const { dragging = false } = props;
|
const { dragging = false } = props;
|
||||||
|
const { isAdmin = false } = props;
|
||||||
|
const { onImageEdit } = props;
|
||||||
const { goTo } = useNavigation();
|
const { goTo } = useNavigation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -38,7 +43,7 @@ export default function ProductItem(props: ProductItemProps) {
|
|||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
padding: "10px",
|
padding: "10px",
|
||||||
border: "solid 1px rgba(0, 0, 0, 0.1)",
|
border: "solid 1px rgba(0, 0, 0, 0.1)",
|
||||||
cursor: "pointer",
|
cursor: isAdmin ? "default" : "pointer",
|
||||||
position: "relative",
|
position: "relative",
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -58,6 +63,11 @@ export default function ProductItem(props: ProductItemProps) {
|
|||||||
display: "block",
|
display: "block",
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
{isAdmin && (
|
||||||
|
<span className={style.adminEditButton} onClick={(e) => { e.stopPropagation(); onImageEdit?.(); }}>
|
||||||
|
<EditIcon fontSize="small" />
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
<ServiceRatingSummary
|
<ServiceRatingSummary
|
||||||
serviceId={product.id}
|
serviceId={product.id}
|
||||||
variant="card"
|
variant="card"
|
||||||
|
|||||||
@@ -8,6 +8,32 @@
|
|||||||
bottom: 8px;
|
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 {
|
.cardHeader {
|
||||||
margin: 10px 0;
|
margin: 10px 0;
|
||||||
text-align: center;
|
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">
|
<div className="homeCentered">
|
||||||
{orgData.id && (
|
{orgData.id && (
|
||||||
<>
|
<>
|
||||||
|
<div style={{ position: "relative" }} id="header-wrapper">
|
||||||
<OrganizationHeader organization={orgData} />
|
<OrganizationHeader organization={orgData} />
|
||||||
|
</div>
|
||||||
<OrganizationDataConnector orgData={orgData} />
|
<OrganizationDataConnector orgData={orgData} />
|
||||||
<div>{children}</div>
|
<div>{children}</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -43,7 +43,10 @@ import { useSessionStore } from "@core/Store/Sesion.Store";
|
|||||||
import { EVENT_TYPES, useEventHandlerStore } from "@core/Store/EventHandler.Store";
|
import { EVENT_TYPES, useEventHandlerStore } from "@core/Store/EventHandler.Store";
|
||||||
import { useAlert } from "@core/Store/Alert.Store";
|
import { useAlert } from "@core/Store/Alert.Store";
|
||||||
import { IPost } from "@core/Models/Posts.model";
|
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 { useSearchParams } from "next/navigation";
|
||||||
|
|
||||||
import { ThemeProvider } from "@emotion/react";
|
import { ThemeProvider } from "@emotion/react";
|
||||||
@@ -55,12 +58,14 @@ import DownIcon from "@mui/icons-material/ArrowDownwardRounded";
|
|||||||
import PinIcon from "@mui/icons-material/PushPin";
|
import PinIcon from "@mui/icons-material/PushPin";
|
||||||
import EditIcon from "@mui/icons-material/AutoFixHigh";
|
import EditIcon from "@mui/icons-material/AutoFixHigh";
|
||||||
import turnosXpressTheme from "@core/app/theme/turnosXpress";
|
import turnosXpressTheme from "@core/app/theme/turnosXpress";
|
||||||
import { useParams } from "next/navigation";
|
import { useParams, useRouter } from "next/navigation";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { useConfirmStore } from "@core/Store/Confirm.Store";
|
import { useConfirmStore } from "@core/Store/Confirm.Store";
|
||||||
import ReviewsCarousel from "@core/app/components/ReviewsCarousel/ReviewsCarousel";
|
import ReviewsCarousel from "@core/app/components/ReviewsCarousel/ReviewsCarousel";
|
||||||
import OrganizationProfessionals from "@core/app/components/OrganizationProfessionals/OrganizationProfessionals";
|
import OrganizationProfessionals from "@core/app/components/OrganizationProfessionals/OrganizationProfessionals";
|
||||||
import { RatingTargetType } from "@core/Models/Ratings.model";
|
import { RatingTargetType } from "@core/Models/Ratings.model";
|
||||||
|
import HeaderEditPopup from "./HeaderEditPopup";
|
||||||
|
import { checkOrgAdmin } from "./post.service";
|
||||||
|
|
||||||
enum VIEW {
|
enum VIEW {
|
||||||
POSTS = "posts",
|
POSTS = "posts",
|
||||||
@@ -76,6 +81,7 @@ type UrlData = {
|
|||||||
export default function OrganizationPublicProfile() {
|
export default function OrganizationPublicProfile() {
|
||||||
const data = useParams<UrlData>();
|
const data = useParams<UrlData>();
|
||||||
const oid = data.oid;
|
const oid = data.oid;
|
||||||
|
const router = useRouter();
|
||||||
const OrganizationData = useOrgDataStore();
|
const OrganizationData = useOrgDataStore();
|
||||||
const [position, setPosition] = useState<[number, number]>([0, 0]);
|
const [position, setPosition] = useState<[number, number]>([0, 0]);
|
||||||
const [orgData, setOrgData] = useState<PublicOrganizationView>();
|
const [orgData, setOrgData] = useState<PublicOrganizationView>();
|
||||||
@@ -96,8 +102,85 @@ export default function OrganizationPublicProfile() {
|
|||||||
const [posts, setPosts] = useState<IPost[]>([]);
|
const [posts, setPosts] = useState<IPost[]>([]);
|
||||||
const [authorizedUsers, setAuthorizedUsers] = useState<string[]>([]);
|
const [authorizedUsers, setAuthorizedUsers] = useState<string[]>([]);
|
||||||
const [currentPage, setCurrentPage] = useState<number>(1);
|
const [currentPage, setCurrentPage] = useState<number>(1);
|
||||||
|
const [isOrgAdmin, setIsOrgAdmin] = useState<boolean>(false);
|
||||||
|
const [showEditPopup, setShowEditPopup] = useState<boolean>(false);
|
||||||
const SessionInfo = useSessionStore();
|
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 eventHandler = useEventHandlerStore();
|
||||||
const alert = useAlert();
|
const alert = useAlert();
|
||||||
const confirm = useConfirmStore();
|
const confirm = useConfirmStore();
|
||||||
@@ -338,7 +421,8 @@ export default function OrganizationPublicProfile() {
|
|||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
const newPosts = response.data.filter(
|
const newPosts = response.data.filter(
|
||||||
(newPost) => !prevPosts.some((prevPost) => prevPost._id === newPost._id),
|
(newPost) =>
|
||||||
|
!prevPosts.some((prevPost) => prevPost._id === newPost._id),
|
||||||
);
|
);
|
||||||
|
|
||||||
return [...prevPosts, ...newPosts];
|
return [...prevPosts, ...newPosts];
|
||||||
@@ -508,7 +592,11 @@ export default function OrganizationPublicProfile() {
|
|||||||
gap: "10px",
|
gap: "10px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<WhatsappShareButton title={shareTitle} separator=":: " url={window.location.href}>
|
<WhatsappShareButton
|
||||||
|
title={shareTitle}
|
||||||
|
separator=":: "
|
||||||
|
url={window.location.href}
|
||||||
|
>
|
||||||
<WhatsAppShareIcon size={32} round />
|
<WhatsAppShareIcon size={32} round />
|
||||||
</WhatsappShareButton>
|
</WhatsappShareButton>
|
||||||
<FacebookShareButton title={shareTitle} url={window.location.href}>
|
<FacebookShareButton title={shareTitle} url={window.location.href}>
|
||||||
@@ -531,6 +619,21 @@ export default function OrganizationPublicProfile() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<HeaderConfProvider />
|
<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 && (
|
{orgData && (
|
||||||
<div className={style.organizationContent}>
|
<div className={style.organizationContent}>
|
||||||
{showEditor && (
|
{showEditor && (
|
||||||
@@ -656,7 +759,9 @@ export default function OrganizationPublicProfile() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{view === VIEW.SERVICES && (
|
{view === VIEW.SERVICES && (
|
||||||
<div style={{ display: "flex", justifyContent: "flex-end" }}>
|
<div
|
||||||
|
style={{ display: "flex", justifyContent: "flex-end" }}
|
||||||
|
>
|
||||||
<ButtonGroup
|
<ButtonGroup
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
aria-label="Basic button group"
|
aria-label="Basic button group"
|
||||||
@@ -711,7 +816,8 @@ export default function OrganizationPublicProfile() {
|
|||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
backgroundImage: "url(/no-conversation.webp)",
|
backgroundImage:
|
||||||
|
"url(/no-conversation.webp)",
|
||||||
backgroundRepeat: "no-repeat",
|
backgroundRepeat: "no-repeat",
|
||||||
backgroundPosition: "center center",
|
backgroundPosition: "center center",
|
||||||
backgroundSize: "50% auto",
|
backgroundSize: "50% auto",
|
||||||
@@ -726,7 +832,8 @@ export default function OrganizationPublicProfile() {
|
|||||||
<div
|
<div
|
||||||
key={post._id}
|
key={post._id}
|
||||||
style={{
|
style={{
|
||||||
borderBottom: "1px solid var(--gray-light)",
|
borderBottom:
|
||||||
|
"1px solid var(--gray-light)",
|
||||||
paddingTop: "5px",
|
paddingTop: "5px",
|
||||||
paddingBottom: "10px",
|
paddingBottom: "10px",
|
||||||
paddingLeft: "30px",
|
paddingLeft: "30px",
|
||||||
@@ -740,7 +847,11 @@ export default function OrganizationPublicProfile() {
|
|||||||
justifyContent: "space-between",
|
justifyContent: "space-between",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div style={{ color: "var(--gray-darkest)" }}>
|
<div
|
||||||
|
style={{
|
||||||
|
color: "var(--gray-darkest)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
{dayjs(post.createdAt).format(
|
{dayjs(post.createdAt).format(
|
||||||
"DD MMMM YYYY HH:mm",
|
"DD MMMM YYYY HH:mm",
|
||||||
)}
|
)}
|
||||||
@@ -780,22 +891,30 @@ export default function OrganizationPublicProfile() {
|
|||||||
color: "var(--gray-darkest)",
|
color: "var(--gray-darkest)",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ThemeProvider theme={turnosXpressTheme}>
|
<ThemeProvider
|
||||||
|
theme={turnosXpressTheme}
|
||||||
|
>
|
||||||
<MaterialButton
|
<MaterialButton
|
||||||
color="inherit"
|
color="inherit"
|
||||||
startIcon={<ClipIcon />}
|
startIcon={<ClipIcon />}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
fijarPost(`${post._id}`);
|
fijarPost(
|
||||||
|
`${post._id}`,
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{post.fixed ? "Liberar" : "Fijar"}
|
{post.fixed
|
||||||
|
? "Liberar"
|
||||||
|
: "Fijar"}
|
||||||
</MaterialButton>
|
</MaterialButton>
|
||||||
|
|
||||||
{post.fixed && (
|
{post.fixed && (
|
||||||
<>
|
<>
|
||||||
<MaterialButton
|
<MaterialButton
|
||||||
color="inherit"
|
color="inherit"
|
||||||
startIcon={<UpIcon />}
|
startIcon={
|
||||||
|
<UpIcon />
|
||||||
|
}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
moverPost(
|
moverPost(
|
||||||
`${post._id}`,
|
`${post._id}`,
|
||||||
@@ -808,7 +927,9 @@ export default function OrganizationPublicProfile() {
|
|||||||
|
|
||||||
<MaterialButton
|
<MaterialButton
|
||||||
color="inherit"
|
color="inherit"
|
||||||
startIcon={<DownIcon />}
|
startIcon={
|
||||||
|
<DownIcon />
|
||||||
|
}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
moverPost(
|
moverPost(
|
||||||
`${post._id}`,
|
`${post._id}`,
|
||||||
@@ -824,7 +945,9 @@ export default function OrganizationPublicProfile() {
|
|||||||
<MaterialButton
|
<MaterialButton
|
||||||
color="inherit"
|
color="inherit"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
editarPost(`${post._id}`);
|
editarPost(
|
||||||
|
`${post._id}`,
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<EditIcon />
|
<EditIcon />
|
||||||
@@ -833,7 +956,9 @@ export default function OrganizationPublicProfile() {
|
|||||||
<MaterialButton
|
<MaterialButton
|
||||||
color="inherit"
|
color="inherit"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
eliminarPost(`${post._id}`);
|
eliminarPost(
|
||||||
|
`${post._id}`,
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
@@ -858,7 +983,8 @@ export default function OrganizationPublicProfile() {
|
|||||||
style={{
|
style={{
|
||||||
padding: "0px 0px 40px 0px",
|
padding: "0px 0px 40px 0px",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: viewMode === "card" ? "row" : "column",
|
flexDirection:
|
||||||
|
viewMode === "card" ? "row" : "column",
|
||||||
justifyContent: "start",
|
justifyContent: "start",
|
||||||
gap: "20px",
|
gap: "20px",
|
||||||
flexWrap: "wrap",
|
flexWrap: "wrap",
|
||||||
|
|||||||
@@ -65,3 +65,7 @@ export const toggleFixedPost = async (data: FixCompanyPostParams): Promise<void>
|
|||||||
export const moveFixedPost = async (data: MoveCompanyFixedPostParams): Promise<void> => {
|
export const moveFixedPost = async (data: MoveCompanyFixedPostParams): Promise<void> => {
|
||||||
return ApiRequest.post<void>("companies/move-fixed-post", data);
|
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 style from "./profile.module.css";
|
||||||
import ApiServerService from "@services/Api.Server.Service";
|
import ApiServerService from "@services/Api.Server.Service";
|
||||||
import { PublicOrganizationServiceView } from "@core/Models/Service.model";
|
import { PublicOrganizationServiceView } from "@core/Models/Service.model";
|
||||||
import ProductItem from "@core/app/components/ProductItem/ProductItem";
|
|
||||||
import Appointment from "./components/Appointment/Appointment";
|
import Appointment from "./components/Appointment/Appointment";
|
||||||
import OrganizationHeader from "@components/Home/OrganizationHeader/OrganizationHeader";
|
import OrganizationHeader from "@components/Home/OrganizationHeader/OrganizationHeader";
|
||||||
import ProductGallery from "@core/app/components/Home/ProductsGallery/ProductGallery";
|
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 EvangelizeBanner from "@components/EvangelizeBanner/EvangelizeBanner";
|
||||||
import ReviewsCarousel from "@components/ReviewsCarousel/ReviewsCarousel";
|
import ReviewsCarousel from "@components/ReviewsCarousel/ReviewsCarousel";
|
||||||
import { RatingTargetType } from "@core/Models/Ratings.model";
|
import { RatingTargetType } from "@core/Models/Ratings.model";
|
||||||
|
import ServiceDetailCard from "./ServiceDetailCard";
|
||||||
|
import OrganizationHeaderEdit from "@components/OrganizationHeaderEdit/OrganizationHeaderEdit";
|
||||||
|
|
||||||
const GetServiceData = async (serviceId: string): Promise<PublicOrganizationServiceView> => {
|
const GetServiceData = async (serviceId: string): Promise<PublicOrganizationServiceView> => {
|
||||||
try {
|
try {
|
||||||
@@ -56,11 +57,20 @@ export default async function OrganizationPublicProfile({ params }: Props) {
|
|||||||
<ScrollToTop />
|
<ScrollToTop />
|
||||||
<HeaderConfProvider />
|
<HeaderConfProvider />
|
||||||
<div className="homeCentered">
|
<div className="homeCentered">
|
||||||
|
<div id="header-wrapper" style={{ position: "relative" }}>
|
||||||
<OrganizationHeader organization={organizationService.organization} />
|
<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.organizationContent}>
|
||||||
<div className={style.serviceSide}>
|
<div className={style.serviceSide}>
|
||||||
<div className={style.stickyWrapper}>
|
<div className={style.stickyWrapper}>
|
||||||
<ProductItem product={organizationService.service} width="100%" />
|
<ServiceDetailCard service={organizationService.service} organization={organizationService.organization} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={style.bookingSide}>
|
<div className={style.bookingSide}>
|
||||||
|
|||||||
Reference in New Issue
Block a user