Skip to content

Commit

Permalink
Merge pull request stakwork#890 from MahtabBukhari/deactivate-update-…
Browse files Browse the repository at this point in the history
…button-unless-a-change-is-made-to-title-or-desription

Deactivate Update (being changed to Save) Button unless a change is made to title or desription
  • Loading branch information
humansinstitute authored Jan 8, 2025
2 parents 4dfd74d + 8fbede8 commit 446441e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/common/TicketEditor/TicketEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const TicketEditor = observer(
const [versionTicketData, setVersionTicketData] = useState<Ticket>(latestTicket as Ticket);
const [isCopying, setIsCopying] = useState(false);
const [activeMode, setActiveMode] = useState<'preview' | 'edit'>('edit');
const [isButtonDisabled, setIsButtonDisabled] = useState(true);
const { main } = useStores();
const [isCreatingBounty, setIsCreatingBounty] = useState(false);
const ui = uiStore;
Expand All @@ -111,6 +112,13 @@ const TicketEditor = observer(
setVersions(versionsArray);
}, [groupTickets, latestTicket?.version]);

useEffect(() => {
const isChanged =
ticketData.name.trim() !== versionTicketData.name.trim() ||
ticketData.description.trim() !== versionTicketData.description.trim();
setIsButtonDisabled(!isChanged);
}, [ticketData, versionTicketData]);

const addUpdateSuccessToast = () => {
setToasts([
{
Expand All @@ -134,6 +142,7 @@ const TicketEditor = observer(
};

const handleUpdate = async () => {
if (isButtonDisabled) return;
try {
const ticketPayload = {
metadata: {
Expand Down Expand Up @@ -409,7 +418,7 @@ const TicketEditor = observer(
onClick={handleUpdate}
data-testid="story-input-update-btn"
>
Update
Save
</ActionButton>
<ActionButton
color="primary"
Expand Down

0 comments on commit 446441e

Please sign in to comment.