UNPKG

@lynsoluciones/medusa-docs

Version:
93 lines (92 loc) 6.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); /* * * * MIT License * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const ui_1 = require("@medusajs/ui"); const material_1 = require("@mui/material"); const medusa_react_1 = require("medusa-react"); const react_hook_form_1 = require("react-hook-form"); const ui_2 = require("@medusajs/ui"); const react_1 = require("react"); const LogoFields = ({ logoSource, register, }) => { const [logoUrl, setLogoUrl] = (0, react_1.useState)(logoSource); const [isValidUrl, setIsValidUrl] = (0, react_1.useState)(true); const [imgLoaded, setIsImageLoaded] = (0, react_1.useState)(false); const handleInputChange = (event) => { setLogoUrl(event.target.value); setIsValidUrl(true); }; const handleImageError = () => { setIsValidUrl(false); setIsImageLoaded(false); }; const handleOnLoad = (event) => { setIsImageLoaded(true); }; return ((0, jsx_runtime_1.jsxs)(material_1.Grid, { container: true, direction: "column", spacing: 1, children: [(0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, children: (0, jsx_runtime_1.jsx)(ui_1.Label, { size: "small", children: "Enlace al logotipo" }) }), (0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, children: (0, jsx_runtime_1.jsx)(ui_1.Input, { placeholder: "https://raw.githubusercontent.com/RSC-Labs/medusa-store-analytics/main/docs/store-analytics-logo.PNG", ...register, defaultValue: logoSource, onChange: handleInputChange }) }), (0, jsx_runtime_1.jsx)(material_1.Grid, { container: true, justifyContent: "center", alignContent: "center", marginTop: 5, children: (0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, children: (0, jsx_runtime_1.jsx)("div", { style: { height: "200px", width: "300px", overflow: "hidden", border: imgLoaded ? undefined : "1px solid rgba(0, 0, 0, 0.12)", }, children: logoUrl && isValidUrl && ((0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, textAlign: "center", children: (0, jsx_runtime_1.jsx)("img", { src: logoUrl, alt: "Preview", style: { maxWidth: 300, maxHeight: 200 }, onLoad: handleOnLoad, onError: handleImageError }) })) }) }) })] })); }; const LogoForm = ({ logoSource, setOpenModal, }) => { const { register, handleSubmit } = (0, react_hook_form_1.useForm)(); const { mutate } = (0, medusa_react_1.useAdminCustomPost)(`/document-settings/logo`, ["logo"]); const onSubmit = (data) => { return mutate({ logoSource: data.logoSource, }, { onSuccess: async ({ response, settings }) => { if (response.status == 201) { if (settings && settings.store_logo_source) { ui_2.toast.success("Logo", { description: "Nuevo logo guardado", }); } else { ui_2.toast.success("Logo", { description: "Logotipo eliminado", }); } setOpenModal(false); } else { ui_2.toast.error("Logo", { description: "El logotipo no se puede guardar, ocurrió algún error.", }); } }, onError: ({}) => { ui_2.toast.error("Logo", { description: "El logotipo no se puede guardar, ocurrió algún error.", }); }, }); }; return ((0, jsx_runtime_1.jsx)("form", { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, { container: true, direction: "column", rowSpacing: 4, paddingTop: 8, children: [(0, jsx_runtime_1.jsx)(LogoFields, { logoSource: logoSource, register: register("logoSource") }), (0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, children: (0, jsx_runtime_1.jsx)(ui_1.Button, { type: "submit", variant: "primary", onClick: handleSubmit(onSubmit), children: "Guardar" }) })] }) })); }; const LogoModalDetails = ({ setOpenModal }) => { const { data, isLoading } = (0, medusa_react_1.useAdminCustomQuery)("/document-settings", [""], {}); if (isLoading) { return ((0, jsx_runtime_1.jsx)(ui_1.FocusModal.Body, { children: (0, jsx_runtime_1.jsx)(material_1.CircularProgress, {}) })); } return ((0, jsx_runtime_1.jsx)(ui_1.FocusModal.Body, { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, { container: true, direction: "column", alignContent: "center", paddingTop: 8, children: [(0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, children: (0, jsx_runtime_1.jsx)(ui_1.Heading, { children: "Logotipo de la tienda" }) }), (0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, children: (0, jsx_runtime_1.jsx)(ui_1.Text, { children: "Este logotipo se utilizar\u00E1 en sus documentos." }) }), (0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, children: (0, jsx_runtime_1.jsx)(ui_1.Text, { children: "La presencia del logotipo en el documento depende de la plantilla." }) }), (0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, children: (0, jsx_runtime_1.jsx)(LogoForm, { logoSource: data.settings && data.settings.store_logo_source ? data.settings.store_logo_source : undefined, setOpenModal: setOpenModal }) })] }) })); }; const LogoChangeModal = () => { const [open, setOpen] = (0, react_1.useState)(false); return ((0, jsx_runtime_1.jsxs)(ui_1.FocusModal, { open: open, onOpenChange: setOpen, children: [(0, jsx_runtime_1.jsx)(ui_1.FocusModal.Trigger, { asChild: true, children: (0, jsx_runtime_1.jsx)(ui_1.Button, { children: "Cambiar logotipo" }) }), (0, jsx_runtime_1.jsxs)(ui_1.FocusModal.Content, { children: [(0, jsx_runtime_1.jsx)(ui_1.FocusModal.Header, {}), (0, jsx_runtime_1.jsx)(LogoModalDetails, { setOpenModal: setOpen })] })] })); }; exports.default = LogoChangeModal;