'use client' import { useState } from 'react' import { postService } from '@/services/postService' import { useToast } from './ui/toast' interface ShareCheckpointButtonProps { checkpointId: string fromCheckpointId?: string aitmProjectId?: string diffSummary?: { added: number; removed: number; modified: number } changedFiles?: string[] title?: string className?: string } export default function ShareCheckpointButton({ checkpointId, fromCheckpointId, aitmProjectId, diffSummary, changedFiles, title, className = '', }: ShareCheckpointButtonProps) { const { showToast } = useToast() const [isOpen, setIsOpen] = useState(false) const [caption, setCaption] = useState('') const [loading, setLoading] = useState(false) const handleShare = async () => { setLoading(true) try { const formData = new FormData() formData.append('content', caption) await postService.createPostWithCheckpoint(formData, { checkpointId, projectId: aitmProjectId || '', fromCheckpointId, diffSummary, changedFiles, changeStoryTitle: title || 'Repository Change Story', }) showToast('Shared as post!', 'success') setIsOpen(false) setCaption('') } catch { showToast('Failed to share checkpoint', 'error') } finally { setLoading(false) } } return (
Share this checkpoint as a Change Story post on your Gitgram feed.