added project estimates events

This commit is contained in:
Lakhan 2024-06-05 14:04:18 +05:30
parent be60b25dad
commit b854e79c51
4 changed files with 50 additions and 12 deletions

View File

@ -8,10 +8,12 @@ import { IEstimate, IEstimateFormData } from "@plane/types";
import { Button, Input, TextArea, TOAST_TYPE, setToast } from "@plane/ui";
// components
import { EModalPosition, EModalWidth, ModalCore } from "@/components/core";
// constants
import { ESTIMATE_CREATED, ESTIMATE_UPDATED } from "constants/event-tracker";
// helpers
import { checkDuplicates } from "@/helpers/array.helper";
// hooks
import { useEstimate } from "@/hooks/store";
import { useEstimate, useEventTracker } from "@/hooks/store";
type Props = {
isOpen: boolean;
@ -39,6 +41,7 @@ export const CreateUpdateEstimateModal: React.FC<Props> = observer((props) => {
const { workspaceSlug, projectId } = router.query;
// store hooks
const { createEstimate, updateEstimate } = useEstimate();
const { captureEvent } = useEventTracker();
// form info
const {
formState: { errors, isSubmitting },
@ -58,8 +61,16 @@ export const CreateUpdateEstimateModal: React.FC<Props> = observer((props) => {
if (!workspaceSlug || !projectId) return;
await createEstimate(workspaceSlug.toString(), projectId.toString(), payload)
.then(() => {
.then((res) => {
onClose();
captureEvent(ESTIMATE_CREATED, {
estimate_id: res.id,
estimate_points: res.points.map((point) => ({
id: point.id,
value: point.value,
key: point.key,
})),
});
})
.catch((err) => {
const error = err?.error;
@ -82,6 +93,10 @@ export const CreateUpdateEstimateModal: React.FC<Props> = observer((props) => {
await updateEstimate(workspaceSlug.toString(), projectId.toString(), data.id, payload)
.then(() => {
onClose();
captureEvent(ESTIMATE_UPDATED, {
estimate_id: data.id,
estimate_points: payload.estimate_points
});
})
.catch((err) => {
const error = err?.error;

View File

@ -7,8 +7,10 @@ import { IEstimate } from "@plane/types";
import { TOAST_TYPE, setToast } from "@plane/ui";
// components
import { AlertModalCore } from "@/components/core";
// constants
import { ESTIMATE_DELETED } from "constants/event-tracker";
// hooks
import { useEstimate } from "@/hooks/store";
import { useEstimate, useEventTracker } from "@/hooks/store";
type Props = {
isOpen: boolean;
@ -25,6 +27,7 @@ export const DeleteEstimateModal: React.FC<Props> = observer((props) => {
const { workspaceSlug, projectId } = router.query;
// store hooks
const { deleteEstimate } = useEstimate();
const { captureEvent } = useEventTracker();
const handleEstimateDelete = async () => {
if (!workspaceSlug || !projectId) return;
@ -37,6 +40,9 @@ export const DeleteEstimateModal: React.FC<Props> = observer((props) => {
await deleteEstimate(workspaceSlug.toString(), projectId.toString(), estimateId)
.then(() => {
handleClose();
captureEvent(ESTIMATE_DELETED, {
estimate_id: estimateId,
});
})
.catch((err) => {
const error = err?.error;

View File

@ -5,8 +5,12 @@ import { useRouter } from "next/router";
import { Pencil, Trash2 } from "lucide-react";
import { IEstimate } from "@plane/types";
import { Button, CustomMenu, TOAST_TYPE, setToast } from "@plane/ui";
// constants
import { ESTIMATE_DISABLED } from "constants/event-tracker";
// helpers
import { orderArrayBy } from "@/helpers/array.helper";
import { useProject } from "@/hooks/store";
// hooks
import { useProject, useEventTracker } from "@/hooks/store";
// ui
//icons
// helpers
@ -25,22 +29,29 @@ export const EstimateListItem: React.FC<Props> = observer((props) => {
const { workspaceSlug, projectId } = router.query;
// store hooks
const { currentProjectDetails, updateProject } = useProject();
const { captureEvent } = useEventTracker();
const handleUseEstimate = async () => {
if (!workspaceSlug || !projectId) return;
await updateProject(workspaceSlug.toString(), projectId.toString(), {
estimate: estimate.id,
}).catch((err) => {
const error = err?.error;
const errorString = Array.isArray(error) ? error[0] : error;
})
.then(() =>
captureEvent(ESTIMATE_DISABLED, {
current_estimate_id: currentProjectDetails?.estimate,
})
)
.catch((err) => {
const error = err?.error;
const errorString = Array.isArray(error) ? error[0] : error;
setToast({
type: TOAST_TYPE.ERROR,
title: "Error!",
message: errorString ?? "Estimate points could not be used. Please try again.",
setToast({
type: TOAST_TYPE.ERROR,
title: "Error!",
message: errorString ?? "Estimate points could not be used. Please try again.",
});
});
});
};
return (

View File

@ -197,6 +197,12 @@ export const MEMBER_ACCEPTED = "Member accepted";
export const PROJECT_MEMBER_ADDED = "Project member added";
export const PROJECT_MEMBER_LEAVE = "Project member leave";
export const WORKSPACE_MEMBER_lEAVE = "Workspace member leave";
// Estimate Events
export const ESTIMATE_CREATED = "Estimate created";
export const ESTIMATE_UPDATED = "Estimate updated";
export const ESTIMATE_DELETED = "Estimate deleted";
export const ESTIMATE_USED = "Estimate used";
export const ESTIMATE_DISABLED = "Estimate disabled";
// Sign-in & Sign-up Events
export const NAVIGATE_TO_SIGNUP = "Navigate to sign-up page";
export const NAVIGATE_TO_SIGNIN = "Navigate to sign-in page";