PromucFlow_constructor/app/client/src/pages/Templates/TemplatesModal/index.tsx
Valera Melnikov 42debc6d11
chore: rename ADS package (#35583)
## Description
Rename `design-system` package to `@appsmith/ads`

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10319507327>
> Commit: 65d9664dd75b750496458a6e1652e0da858e1fc6
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10319507327&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Fri, 09 Aug 2024 13:47:50 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No
2024-08-09 17:20:29 +03:00

113 lines
3.4 KiB
TypeScript

import React, { useEffect, useState } from "react";
import styled from "styled-components";
import { useDispatch, useSelector } from "react-redux";
import {
allTemplatesFiltersSelector,
templateModalSelector,
templatesCountSelector,
} from "selectors/templatesSelectors";
import {
getAllTemplates,
getTemplateFilters,
hideTemplatesModal,
} from "actions/templateActions";
import { fetchDefaultPlugins } from "actions/pluginActions";
import TemplateDetailedView from "./TemplateDetailedView";
import { isEmpty } from "lodash";
import type { AppState } from "ee/reducers";
import { Modal, ModalBody, ModalContent, ModalHeader } from "@appsmith/ads";
import TemplateModalHeader from "./Header";
import { ReduxActionTypes } from "ee/constants/ReduxActionConstants";
import TemplatesListLayoutSwitcher from "./TemplatesListLayoutSwitcher";
const ModalContentWrapper = styled(ModalContent)`
width: 100%;
overflow-y: hidden;
background-color: var(--ads-v2-color-gray-50);
`;
const ModalBodyWrapper = styled(ModalBody)`
width: 100%;
overflow-y: hidden;
`;
function TemplatesModal() {
const templatesModalInfo = useSelector(templateModalSelector);
const dispatch = useDispatch();
const templatesCount = useSelector(templatesCountSelector);
const pluginListLength = useSelector(
(state: AppState) => state.entities.plugins.defaultPluginList.length,
);
const filters = useSelector(allTemplatesFiltersSelector);
const [showTemplateDetails, setShowTemplateDetails] = useState("");
useEffect(() => {
setShowTemplateDetails("");
if (templatesModalInfo.isOpen) {
dispatch({
type: ReduxActionTypes.RESET_TEMPLATE_FILTERS,
});
}
}, [templatesModalInfo]);
useEffect(() => {
if (!templatesCount && templatesModalInfo) {
dispatch(getAllTemplates());
}
}, [templatesCount, templatesModalInfo]);
useEffect(() => {
if (!pluginListLength) {
dispatch(fetchDefaultPlugins());
}
}, [pluginListLength]);
useEffect(() => {
if (isEmpty(filters.functions)) {
dispatch(getTemplateFilters());
}
}, [filters]);
const onClose = (open: boolean) => {
if (open === false) {
dispatch(hideTemplatesModal());
setShowTemplateDetails("");
}
};
const onTemplateClick = (id: string) => {
setShowTemplateDetails(id);
};
return (
<Modal
onOpenChange={(open) => onClose(open)}
open={templatesModalInfo.isOpen}
>
<ModalContentWrapper data-testid="t--templates-dialog-component">
<ModalHeader>
<TemplateModalHeader
className={!showTemplateDetails ? "modal-header" : ""}
/>
</ModalHeader>
<ModalBodyWrapper>
{!!showTemplateDetails ? (
<TemplateDetailedView
isStartWithTemplateFlow={templatesModalInfo.isOpenFromCanvas}
onBackPress={() => setShowTemplateDetails("")}
onClose={() => onClose(false)}
templateId={showTemplateDetails}
/>
) : (
<TemplatesListLayoutSwitcher
analyticsEventNameForTemplateCardClick="TEMPLATE_ADD_PAGE_FROM_TEMPLATE_FLOW"
isStartWithTemplateFlow={templatesModalInfo.isOpenFromCanvas}
onTemplateClick={onTemplateClick}
/>
)}
</ModalBodyWrapper>
</ModalContentWrapper>
</Modal>
);
}
export default TemplatesModal;