PromucFlow_constructor/app/client/src/pages/Templates/ForkTemplate.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

104 lines
2.8 KiB
TypeScript

import type { ReactNode } from "react";
import React, { useState } from "react";
import {
Button,
Modal,
ModalBody,
ModalContent,
ModalFooter,
ModalHeader,
Select,
} from "@appsmith/ads";
import { useDispatch, useSelector } from "react-redux";
import {
getForkableWorkspaces,
isImportingTemplateSelector,
} from "selectors/templatesSelectors";
import { importTemplateToWorkspace } from "actions/templateActions";
import {
CANCEL,
CHOOSE_WHERE_TO_FORK,
createMessage,
FORK_TEMPLATE,
SELECT_WORKSPACE,
} from "ee/constants/messages";
interface ForkTemplateProps {
children?: ReactNode;
showForkModal: boolean;
onClose: (e?: React.MouseEvent<HTMLElement>) => void;
templateId: string;
}
function ForkTemplate({
children,
onClose,
showForkModal,
templateId,
}: ForkTemplateProps) {
const workspaceList = useSelector(getForkableWorkspaces);
const [selectedWorkspace, setSelectedWorkspace] = useState(workspaceList[0]);
const isImportingTemplate = useSelector(isImportingTemplateSelector);
const dispatch = useDispatch();
const onFork = () => {
dispatch(importTemplateToWorkspace(templateId, selectedWorkspace.value));
};
const closeModal = (isOpen: boolean) => {
if (!isOpen && !isImportingTemplate) {
onClose();
}
};
return (
<>
{children}
<Modal onOpenChange={closeModal} open={showForkModal}>
<ModalContent style={{ width: "640px" }}>
<ModalHeader>{createMessage(CHOOSE_WHERE_TO_FORK)}</ModalHeader>
<ModalBody style={{ overflow: "unset", paddingBottom: "4px" }}>
<Select
dropdownMatchSelectWidth
getPopupContainer={(triggerNode) => triggerNode.parentNode}
// TODO: (Albin) Fix this
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
onSelect={(
dropdownOptionValue: string,
dropdownOption: {
label: string;
value: string;
},
) => setSelectedWorkspace(dropdownOption)}
options={workspaceList}
placeholder={createMessage(SELECT_WORKSPACE)}
value={selectedWorkspace}
/>
</ModalBody>
<ModalFooter>
<Button
isDisabled={isImportingTemplate}
kind="secondary"
onClick={onClose}
size="md"
>
{createMessage(CANCEL)}
</Button>
<Button
className="t--fork-template-button"
isLoading={isImportingTemplate}
onClick={onFork}
size="md"
>
{createMessage(FORK_TEMPLATE)}
</Button>
</ModalFooter>
</ModalContent>
</Modal>
</>
);
}
export default ForkTemplate;