feat: cards, attributes and modules
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import { useState } from "react";
|
||||
|
||||
import styles from "./CreateDealButton.module.css";
|
||||
import { Text, Transition } from "@mantine/core";
|
||||
import CreateCardForm from "../CreateCardForm/CreateCardForm.tsx";
|
||||
import { CardService, StatusSchema } from "../../../../client";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { dateWithoutTimezone } from "../../../../shared/lib/date.ts";
|
||||
import { usePrefillCardContext } from "../../../../pages/CardsPage/contexts/PrefillCardContext.tsx";
|
||||
import { useCardPageContext } from "../../../../pages/CardsPage/contexts/CardPageContext.tsx";
|
||||
import isModuleInProject, { Modules } from "../../../../pages/CardsPage/utils/isModuleInProject.ts";
|
||||
|
||||
type Props = {
|
||||
status: StatusSchema;
|
||||
}
|
||||
|
||||
const CreateCardButton = ({ status }: Props) => {
|
||||
const [isCreating, setIsCreating] = useState(false);
|
||||
const [isTransitionEnded, setIsTransitionEnded] = useState(true);
|
||||
const queryClient = useQueryClient();
|
||||
const { prefillCard, setPrefillCard } = usePrefillCardContext();
|
||||
|
||||
const { selectedProject } = useCardPageContext();
|
||||
const isPrefillingDealEnabled = isModuleInProject(Modules.SERVICES_AND_PRODUCTS, selectedProject);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={styles["container"]}
|
||||
onClick={() => {
|
||||
if (isCreating) return;
|
||||
setIsCreating(prevState => !prevState);
|
||||
setIsTransitionEnded(false);
|
||||
}}>
|
||||
{!isCreating && isTransitionEnded && (
|
||||
<Text>Быстрое добавление</Text>
|
||||
)}
|
||||
<Transition
|
||||
mounted={isCreating}
|
||||
transition={"scale-y"}
|
||||
onExited={() => setIsTransitionEnded(true)}>
|
||||
{styles => (
|
||||
<div style={styles}>
|
||||
<CreateCardForm
|
||||
onCancel={() => {
|
||||
setPrefillCard(undefined);
|
||||
setIsCreating(false);
|
||||
}}
|
||||
onSubmit={quickDeal => {
|
||||
CardService.quickCreateCardQuickCreatePost({
|
||||
requestBody: {
|
||||
...quickDeal,
|
||||
acceptanceDate: dateWithoutTimezone(
|
||||
quickDeal.acceptanceDate,
|
||||
),
|
||||
statusId: status.id,
|
||||
},
|
||||
}).then(async (result) => {
|
||||
if (isPrefillingDealEnabled && prefillCard) {
|
||||
CardService.prefillCard({
|
||||
requestBody: {
|
||||
oldCardId: prefillCard.id,
|
||||
newCardId: result.cardId,
|
||||
},
|
||||
});
|
||||
}
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: ["getCardSummaries"],
|
||||
});
|
||||
setIsCreating(false);
|
||||
setPrefillCard(undefined);
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Transition>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
export default CreateCardButton;
|
||||
Reference in New Issue
Block a user