Skip to content

Commit

Permalink
Merge pull request stakwork#861 from Ekep-Obasi/ticket-to-bounty-conv…
Browse files Browse the repository at this point in the history
…ersion

Implement Ticket-to-Bounty Conversion
  • Loading branch information
humansinstitute authored Jan 4, 2025
2 parents a44cedb + b9134f4 commit 47c99e4
Show file tree
Hide file tree
Showing 3 changed files with 630 additions and 551 deletions.
47 changes: 47 additions & 0 deletions src/components/common/TicketEditor/TicketEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@elastic/eui';
import { renderMarkdown } from 'people/utils/RenderMarkdown.tsx';
import styled from 'styled-components';
import history from 'config/history.ts';
import { phaseTicketStore } from '../../../store/phase';
import {
ActionButton,
Expand Down Expand Up @@ -92,6 +93,7 @@ const TicketEditor = observer(
const [isCopying, setIsCopying] = useState(false);
const [activeMode, setActiveMode] = useState<'preview' | 'edit'>('edit');
const { main } = useStores();
const [isCreatingBounty, setIsCreatingBounty] = useState(false);
const ui = uiStore;

const groupTickets = useMemo(
Expand Down Expand Up @@ -277,6 +279,43 @@ const TicketEditor = observer(
setIsCopying(false);
}
};

const handleCreateBounty = async () => {
if (isCreatingBounty) return;

setIsCreatingBounty(true);
try {
const data = await main.createBountyFromTicket(ticketData.uuid);

if (data?.success) {
setToasts([
{
id: `${Date.now()}-bounty-success`,
title: 'Bounty Created',
color: 'success',
text: 'Bounty created successfully!'
}
]);

history.push(`/bounty/${data.bounty_id}`);
} else {
throw new Error('Failed to create bounty');
}
} catch (error) {
console.error('Error creating bounty:', error);
setToasts([
{
id: `${Date.now()}-bounty-error`,
title: 'Error',
color: 'danger',
text: 'Failed to create bounty'
}
]);
} finally {
setIsCreatingBounty(false);
}
};

return (
<TicketContainer>
<EuiFlexGroup alignItems="center" gutterSize="s">
Expand Down Expand Up @@ -372,6 +411,14 @@ const TicketEditor = observer(
>
Update
</ActionButton>
<ActionButton
color="primary"
onClick={handleCreateBounty}
disabled={isCreatingBounty}
data-testid="create-bounty-from-ticket-btn"
>
{isCreatingBounty ? 'Creating Bounty...' : 'Create Bounty'}
</ActionButton>
{swwfLink && (
<ActionButton
as="a"
Expand Down
Loading

0 comments on commit 47c99e4

Please sign in to comment.