* feat: implemented addOrRemoveLabel mutation on CardPage to automatically add new labels #266 * Remove .env.backup
This commit is contained in:
committed by
GitHub
parent
06ca6e38b3
commit
88f1aa0ec4
@@ -147,6 +147,7 @@ export default function CardPage({ isTemplate }: { isTemplate?: boolean }) {
|
|||||||
getModalState,
|
getModalState,
|
||||||
clearModalState,
|
clearModalState,
|
||||||
isOpen,
|
isOpen,
|
||||||
|
modalStates,
|
||||||
} = useModal();
|
} = useModal();
|
||||||
const { showPopup } = usePopup();
|
const { showPopup } = usePopup();
|
||||||
const { workspace } = useWorkspace();
|
const { workspace } = useWorkspace();
|
||||||
@@ -183,6 +184,21 @@ export default function CardPage({ isTemplate }: { isTemplate?: boolean }) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const addOrRemoveLabel = api.card.addOrRemoveLabel.useMutation({
|
||||||
|
onError: () => {
|
||||||
|
showPopup({
|
||||||
|
header: t`Unable to add label`,
|
||||||
|
message: t`Please try again later, or contact customer support.`,
|
||||||
|
icon: "error",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onSettled: async () => {
|
||||||
|
if (cardId) {
|
||||||
|
await utils.card.byId.invalidate({ cardPublicId: cardId });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const { register, handleSubmit, setValue, watch } = useForm<FormValues>({
|
const { register, handleSubmit, setValue, watch } = useForm<FormValues>({
|
||||||
values: {
|
values: {
|
||||||
cardId: cardId ?? "",
|
cardId: cardId ?? "",
|
||||||
@@ -199,6 +215,24 @@ export default function CardPage({ isTemplate }: { isTemplate?: boolean }) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// this adds the new created label to selected labels
|
||||||
|
useEffect(() => {
|
||||||
|
const newLabelId = modalStates.NEW_LABEL_CREATED;
|
||||||
|
if (newLabelId && cardId) {
|
||||||
|
const isAlreadyAdded = card?.labels.some(
|
||||||
|
(label) => label.publicId === newLabelId,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isAlreadyAdded) {
|
||||||
|
addOrRemoveLabel.mutate({
|
||||||
|
cardPublicId: cardId,
|
||||||
|
labelPublicId: newLabelId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
clearModalState("NEW_LABEL_CREATED");
|
||||||
|
}
|
||||||
|
}, [modalStates.NEW_LABEL_CREATED, card, cardId]);
|
||||||
|
|
||||||
// Open the new item form after creating a new checklist
|
// Open the new item form after creating a new checklist
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!card) return;
|
if (!card) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user