Skip to content

Commit

Permalink
feat: add copy content (#8001)
Browse files Browse the repository at this point in the history
  • Loading branch information
arikchakma authored Jan 20, 2025
1 parent 2640c82 commit 22f29a1
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions src/components/CreateTeam/RoadmapSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
} from '../CustomRoadmap/CreateRoadmap/CreateRoadmapModal';
import { CreateRoadmapModal } from '../CustomRoadmap/CreateRoadmap/CreateRoadmapModal';
import { useToast } from '../../hooks/use-toast';
import { ContentConfirmationModal } from './ContentConfirmationModal';

export type TeamResourceConfig = {
isCustomResource: boolean;
Expand Down Expand Up @@ -44,6 +45,7 @@ export function RoadmapSelector(props: RoadmapSelectorProps) {
const [isCreatingRoadmap, setIsCreatingRoadmap] = useState<boolean>(false);

const [error, setError] = useState<string>('');
const [confirmationContentId, setConfirmationContentId] = useState<string>();

async function loadAllRoadmaps() {
const { error, response } = await httpGet<PageType[]>(`/pages.json`);
Expand Down Expand Up @@ -101,7 +103,7 @@ export function RoadmapSelector(props: RoadmapSelectorProps) {
});
}

async function addTeamResource(roadmapId: string) {
async function addTeamResource(roadmapId: string, shouldCopyContent = false) {
if (!teamId) {
return;
}
Expand All @@ -118,6 +120,7 @@ export function RoadmapSelector(props: RoadmapSelectorProps) {
resourceType: 'roadmap',
removed: [],
renderer: renderer || 'balsamiq',
shouldCopyContent,
},
);

Expand Down Expand Up @@ -148,8 +151,24 @@ export function RoadmapSelector(props: RoadmapSelectorProps) {
});
}

const confirmationContentIdModal = confirmationContentId && (
<ContentConfirmationModal
onClose={() => {
setConfirmationContentId('');
}}
onClick={(shouldCopy) => {
addTeamResource(confirmationContentId, shouldCopy).finally(() => {
pageProgressMessage.set('');
setConfirmationContentId('');
});
}}
/>
);

return (
<div>
{confirmationContentIdModal}

{changingRoadmapId && (
<UpdateTeamResourceModal
onClose={() => setChangingRoadmapId('')}
Expand All @@ -170,9 +189,20 @@ export function RoadmapSelector(props: RoadmapSelectorProps) {
allRoadmaps={allRoadmaps.filter((r) => r.renderer === 'editor')}
teamId={teamId}
onRoadmapAdd={(roadmapId) => {
addTeamResource(roadmapId).finally(() => {
pageProgressMessage.set('');
});
const isEditorRoadmap = allRoadmaps.find(
(r) => r.id === roadmapId && r.renderer === 'editor',
);

if (!isEditorRoadmap) {
addTeamResource(roadmapId).finally(() => {
pageProgressMessage.set('');
});

return;
}

setShowSelectRoadmapModal(false);
setConfirmationContentId(roadmapId);
}}
onRoadmapRemove={(roadmapId) => {
onRemove(roadmapId).finally(() => {});
Expand Down

0 comments on commit 22f29a1

Please sign in to comment.