Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: track events issue and env variables fixes #2184

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
"NEXT_PUBLIC_UNSPLASH_ACCESS",
"NEXT_PUBLIC_UNSPLASH_ENABLED",
"NEXT_PUBLIC_TRACK_EVENTS",
"TRACKER_ACCESS_KEY",
"NEXT_PUBLIC_PLAUSIBLE_DOMAIN",
"NEXT_PUBLIC_CRISP_ID",
"NEXT_PUBLIC_ENABLE_SESSION_RECORDER",
"NEXT_PUBLIC_SESSION_RECORDER_KEY",
"NEXT_PUBLIC_EXTRA_IMAGE_DOMAINS",
"NEXT_PUBLIC_SLACK_CLIENT_ID",
"NEXT_PUBLIC_SLACK_CLIENT_SECRET",
"NEXT_PUBLIC_SUPABASE_URL",
"NEXT_PUBLIC_SUPABASE_ANON_KEY",
"NEXT_PUBLIC_PLAUSIBLE_DOMAIN",
"NEXT_PUBLIC_DEPLOY_WITH_NGINX"
"NEXT_PUBLIC_DEPLOY_WITH_NGINX",
"SLACK_OAUTH_URL",
"SLACK_CLIENT_ID",
"SLACK_CLIENT_SECRET",
"JITSU_TRACKER_ACCESS_KEY",
"JITSU_TRACKER_HOST",
"UNSPLASH_ACCESS_KEY"
],
"pipeline": {
"build": {
Expand Down
6 changes: 1 addition & 5 deletions web/components/workspace/sidebar-dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Fragment } from "react";

import { useRouter } from "next/router";
import Link from "next/link";

// headless ui
import { Menu, Transition } from "@headlessui/react";
// next-themes
Expand Down Expand Up @@ -63,8 +61,6 @@ export const WorkspaceSidebarDropdown = () => {

const { user, mutateUser } = useUser();

const { collapsed: sidebarCollapse } = useThemeHook();

const { setTheme } = useTheme();

const { setToastAlert } = useToast();
Expand Down Expand Up @@ -155,7 +151,7 @@ export const WorkspaceSidebarDropdown = () => {
{workspaces.length > 0 ? (
workspaces.map((workspace) => (
<Menu.Item key={workspace.id}>
{({ active }) => (
{() => (
<button
type="button"
onClick={() => handleWorkspaceNavigation(workspace)}
Expand Down
3 changes: 0 additions & 3 deletions web/components/workspace/sidebar-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import React from "react";

import Link from "next/link";
import { useRouter } from "next/router";

// hooks
import useTheme from "hooks/use-theme";
// components
import { NotificationPopover } from "components/notifications";
// ui
import { Tooltip } from "components/ui";
// icons
import {
Expand Down
2 changes: 1 addition & 1 deletion web/components/workspace/single-invitation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const SingleInvitation: React.FC<Props> = ({
? "bg-custom-background-80 text-custom-text-200"
: "bg-custom-primary text-white"
} text-sm px-4 py-2 border border-custom-border-200 rounded-3xl`}
onClick={(e) => {
onClick={() => {
handleInvitation(
invitation,
invitationsRespond.includes(invitation.id) ? "withdraw" : "accepted"
Expand Down
2 changes: 0 additions & 2 deletions web/lib/mobx/store-init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { useEffect } from "react";
import { useTheme } from "next-themes";
// mobx store
import { useMobxStore } from "lib/mobx/store-provider";
// theme helpers
import { applyTheme, unsetCustomCssVariables } from "helpers/theme.helper";

const MobxStoreInit = () => {
const store: any = useMobxStore();
Expand Down
1 change: 1 addition & 0 deletions web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require("dotenv").config({ path: ".env" });

const { withSentryConfig } = require("@sentry/nextjs");
const path = require("path");

const extraImageDomains = (process.env.NEXT_PUBLIC_EXTRA_IMAGE_DOMAINS ?? "")
.split(",")
.filter((domain) => domain.length > 0);
Expand Down
7 changes: 2 additions & 5 deletions web/pages/[workspaceSlug]/me/profile/preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@ import { ICustomTheme } from "types";
import { observer } from "mobx-react-lite";
// mobx store
import { useMobxStore } from "lib/mobx/store-provider";
// next themes
import { useTheme } from "next-themes";

const ProfilePreferences = observer(() => {
const { user: myProfile } = useUserAuth();

const store: any = useMobxStore();
const { theme } = useTheme();

console.log("store", store?.theme?.theme);
console.log("theme", theme);
// console.log("store", store?.theme?.theme);
// console.log("theme", theme);

const [customThemeSelectorOptions, setCustomThemeSelectorOptions] = useState(false);

Expand Down
32 changes: 16 additions & 16 deletions web/pages/api/slack-redirect.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
// pages/api/slack/authorize.js
import axios from "axios";
import { NextApiRequest, NextApiResponse } from "next";

export default async function handleSlackAuthorize(req: NextApiRequest, res: NextApiResponse) {
const { code } = req.body;
try {
const { code } = req.body;

if (!code || code === "") return res.status(400).json({ message: "Code is required" });
if (!code || code === "") return res.status(400).json({ message: "Code is required" });

const response = await axios({
method: "post",
url: "https://slack.com/api/oauth.v2.access",
params: {
client_id: process.env.NEXT_PUBLIC_SLACK_CLIENT_ID,
client_secret: process.env.NEXT_PUBLIC_SLACK_CLIENT_SECRET,
code,
},
});

// if (response?.data?.ok)
res.status(200).json(response.data);
// else res.status(404).json(response.data);
const response = await axios({
method: "post",
url: process.env.SLACK_OAUTH_URL || "",
params: {
client_id: process.env.SLACK_CLIENT_ID,
client_secret: process.env.SLACK_CLIENT_SECRET,
code,
},
});
res.status(200).json(response?.data);
} catch (error) {
res.status(200).json({ message: "Internal Server Error" });
}
}
22 changes: 9 additions & 13 deletions web/pages/api/track-event.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { NextApiRequest, NextApiResponse } from "next";

// jitsu
import { createClient } from "@jitsu/nextjs";
import { convertCookieStringToObject } from "lib/cookie";

const jitsu = createClient({
key: process.env.TRACKER_ACCESS_KEY || "",
tracking_host: "https://t.jitsu.com",
const jitsuClient = createClient({
key: process.env.JITSU_TRACKER_ACCESS_KEY || "",
tracking_host: process.env.JITSU_TRACKER_HOST || "",
});

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
Expand All @@ -18,18 +16,16 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)

if (!user) return res.status(401).json({ message: "Unauthorized" });

// TODO: cache user info

jitsu
jitsuClient
.id({
id: user.id,
email: user.email,
first_name: user.first_name,
last_name: user.last_name,
id: user?.id,
email: user?.email,
first_name: user?.first_name,
last_name: user?.last_name,
display_name: user?.display_name,
})
.then(() => {
jitsu.track(eventName, {
jitsuClient.track(eventName, {
...extra,
});
});
Expand Down
11 changes: 5 additions & 6 deletions web/pages/api/unsplash.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from "axios";
import type { NextApiRequest, NextApiResponse } from "next";

// TODO: remove NEXT_PUBLIC_ prefix from env variable
const unsplashKey = process.env.NEXT_PUBLIC_UNSPLASH_ACCESS;
const unsplashKey = process.env.UNSPLASH_ACCESS_KEY;

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const { query, page, per_page = 20 } = req.query;
Expand All @@ -10,14 +10,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
? `https://api.unsplash.com/search/photos/?client_id=${unsplashKey}&query=${query}&page=${page}&per_page=${per_page}`
: `https://api.unsplash.com/photos/?client_id=${unsplashKey}&page=${page}&per_page=${per_page}`;

const response = await fetch(url, {
const response = await axios({
method: "GET",
url,
headers: {
"Content-Type": "application/json",
},
});

const data = await response.json();

res.status(200).json(data);
res.status(200).json(response);
}
5 changes: 1 addition & 4 deletions web/services/ai.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import { ICurrentUserResponse, IGptResponse } from "types";
// helpers
import { API_BASE_URL } from "helpers/common.helper";

const trackEvent =
process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1";

class AiServices extends APIService {
constructor() {
super(API_BASE_URL);
Expand All @@ -21,7 +18,7 @@ class AiServices extends APIService {
): Promise<IGptResponse> {
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/ai-assistant/`, data)
.then((response) => {
if (trackEvent) trackEventServices.trackAskGptEvent(response?.data, "ASK_GPT", user);
trackEventServices.trackAskGptEvent(response?.data, "ASK_GPT", user);
return response?.data;
})
.catch((error) => {
Expand Down
11 changes: 4 additions & 7 deletions web/services/cycles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import trackEventServices from "services/track-event.service";
import type { CycleDateCheckData, ICurrentUserResponse, ICycle, IIssue } from "types";
import { API_BASE_URL } from "helpers/common.helper";

const trackEvent =
process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1";

class ProjectCycleServices extends APIService {
constructor() {
super(API_BASE_URL);
Expand All @@ -21,7 +18,7 @@ class ProjectCycleServices extends APIService {
): Promise<any> {
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/cycles/`, data)
.then((response) => {
if (trackEvent) trackEventServices.trackCycleEvent(response?.data, "CYCLE_CREATE", user);
trackEventServices.trackCycleEvent(response?.data, "CYCLE_CREATE", user);
return response?.data;
})
.catch((error) => {
Expand Down Expand Up @@ -99,7 +96,7 @@ class ProjectCycleServices extends APIService {
data
)
.then((response) => {
if (trackEvent) trackEventServices.trackCycleEvent(response?.data, "CYCLE_UPDATE", user);
trackEventServices.trackCycleEvent(response?.data, "CYCLE_UPDATE", user);
return response?.data;
})
.catch((error) => {
Expand All @@ -119,7 +116,7 @@ class ProjectCycleServices extends APIService {
data
)
.then((response) => {
if (trackEvent) trackEventServices.trackCycleEvent(response?.data, "CYCLE_UPDATE", user);
trackEventServices.trackCycleEvent(response?.data, "CYCLE_UPDATE", user);
return response?.data;
})
.catch((error) => {
Expand All @@ -135,7 +132,7 @@ class ProjectCycleServices extends APIService {
): Promise<any> {
return this.delete(`/api/workspaces/${workspaceSlug}/projects/${projectId}/cycles/${cycleId}/`)
.then((response) => {
if (trackEvent) trackEventServices.trackCycleEvent(response?.data, "CYCLE_DELETE", user);
trackEventServices.trackCycleEvent(response?.data, "CYCLE_DELETE", user);
return response?.data;
})
.catch((error) => {
Expand Down
12 changes: 3 additions & 9 deletions web/services/estimates.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import type { ICurrentUserResponse, IEstimate, IEstimateFormData } from "types";
import trackEventServices from "services/track-event.service";
import { API_BASE_URL } from "helpers/common.helper";

const trackEvent =
process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1";

class ProjectEstimateServices extends APIService {
constructor() {
super(API_BASE_URL);
Expand All @@ -21,8 +18,7 @@ class ProjectEstimateServices extends APIService {
): Promise<any> {
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/`, data)
.then((response) => {
if (trackEvent)
trackEventServices.trackIssueEstimateEvent(response?.data, "ESTIMATE_CREATE", user);
trackEventServices.trackIssueEstimateEvent(response?.data, "ESTIMATE_CREATE", user);
return response?.data;
})
.catch((error) => {
Expand All @@ -42,8 +38,7 @@ class ProjectEstimateServices extends APIService {
data
)
.then((response) => {
if (trackEvent)
trackEventServices.trackIssueEstimateEvent(response?.data, "ESTIMATE_UPDATE", user);
trackEventServices.trackIssueEstimateEvent(response?.data, "ESTIMATE_UPDATE", user);
return response?.data;
})
.catch((error) => {
Expand Down Expand Up @@ -83,8 +78,7 @@ class ProjectEstimateServices extends APIService {
`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/${estimateId}/`
)
.then((response) => {
if (trackEvent)
trackEventServices.trackIssueEstimateEvent(response?.data, "ESTIMATE_DELETE", user);
trackEventServices.trackIssueEstimateEvent(response?.data, "ESTIMATE_DELETE", user);
return response?.data;
})
.catch((error) => {
Expand Down
16 changes: 4 additions & 12 deletions web/services/inbox.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import APIService from "services/api.service";
import trackEventServices from "services/track-event.service";
import { API_BASE_URL } from "helpers/common.helper";

const trackEvent =
process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1";

// types
import type {
IInboxIssue,
IInbox,
TInboxStatus,
IInboxIssueDetail,
ICurrentUserResponse,
IInboxFilterOptions,
IInboxQueryParams,
} from "types";

Expand Down Expand Up @@ -95,8 +90,7 @@ class InboxServices extends APIService {
`/api/workspaces/${workspaceSlug}/projects/${projectId}/inboxes/${inboxId}/inbox-issues/${inboxIssueId}/`
)
.then((response) => {
if (trackEvent)
trackEventServices.trackInboxEvent(response?.data, "INBOX_ISSUE_DELETE", user);
trackEventServices.trackInboxEvent(response?.data, "INBOX_ISSUE_DELETE", user);
return response?.data;
})
.catch((error) => {
Expand Down Expand Up @@ -125,7 +119,7 @@ class InboxServices extends APIService {
: data.status === 1
? "INBOX_ISSUE_ACCEPTED"
: "INBOX_ISSUE_DUPLICATED";
if (trackEvent) trackEventServices.trackInboxEvent(response?.data, action, user);
trackEventServices.trackInboxEvent(response?.data, action, user);
return response?.data;
})
.catch((error) => {
Expand All @@ -146,8 +140,7 @@ class InboxServices extends APIService {
data
)
.then((response) => {
if (trackEvent)
trackEventServices.trackInboxEvent(response?.data, "INBOX_ISSUE_UPDATE", user);
trackEventServices.trackInboxEvent(response?.data, "INBOX_ISSUE_UPDATE", user);
return response?.data;
})
.catch((error) => {
Expand All @@ -167,8 +160,7 @@ class InboxServices extends APIService {
data
)
.then((response) => {
if (trackEvent)
trackEventServices.trackInboxEvent(response?.data, "INBOX_ISSUE_CREATE", user);
trackEventServices.trackInboxEvent(response?.data, "INBOX_ISSUE_CREATE", user);
return response?.data;
})
.catch((error) => {
Expand Down
Loading
Loading