Skip to content

Commit c2a036d

Browse files
authored
Merge pull request #100 from techulus/develop
Fix auth for reactions
2 parents 6f396ae + 9003bae commit c2a036d

File tree

8 files changed

+39
-54
lines changed

8 files changed

+39
-54
lines changed

apps/page/components/footer.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { IPageSettings } from "@changes-page/supabase/types/page";
22
import Image from "next/image";
33
import { useEffect } from "react";
4+
import { PageRoadmap } from "../lib/data";
45
import appStoreBadgeLight from "../public/badges/App_Store_Badge_US-UK_RGB_blk.svg";
56
import appStoreBadgeDark from "../public/badges/App_Store_Badge_US-UK_RGB_wht.svg";
67
import googlePlayBadge from "../public/badges/google-play-badge.png";
@@ -16,7 +17,13 @@ import {
1617
} from "./social-icons.component";
1718
import VisitorStatus from "./visitor-status";
1819

19-
export default function Footer({ settings }: { settings: IPageSettings }) {
20+
export default function Footer({
21+
settings,
22+
roadmaps = [],
23+
}: {
24+
settings: IPageSettings;
25+
roadmaps?: PageRoadmap[];
26+
}) {
2027
useEffect(() => {
2128
httpPost({
2229
url: "/api/pa/view",
@@ -26,9 +33,11 @@ export default function Footer({ settings }: { settings: IPageSettings }) {
2633

2734
return (
2835
<footer>
29-
<div className="pt-4 py-2 flex justify-center space-x-6">
30-
<VisitorStatus />
31-
</div>
36+
{(roadmaps ?? []).length ? (
37+
<div className="pt-4 py-2 flex justify-center space-x-6">
38+
<VisitorStatus />
39+
</div>
40+
) : null}
3241

3342
{(settings?.app_store_url || settings?.play_store_url) && (
3443
<p className="pt-4 py-4 flex justify-center space-x-6">

apps/page/components/reactions.tsx

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { Transition } from "@headlessui/react";
33
import classNames from "classnames";
44
import { useCallback, useEffect, useState } from "react";
55
import { httpGet, httpPost } from "../utils/http";
6-
import { useVisitorAuth } from "../hooks/useVisitorAuth";
7-
import VisitorAuthModal from "./visitor-auth-modal";
86

97
const ReactionsCounter = ({
108
postId,
@@ -13,23 +11,16 @@ const ReactionsCounter = ({
1311
floating,
1412
optimisticUpdate,
1513
setShowPicker,
16-
onAuthRequired,
1714
}: {
1815
postId: string;
1916
aggregate: IReactions;
2017
user: IReactions;
2118
floating: boolean;
2219
optimisticUpdate?: (reaction: string, status: boolean) => void;
2320
setShowPicker?: (v: boolean) => void;
24-
onAuthRequired?: () => void;
2521
}) => {
2622
const doReact = useCallback(
2723
(reaction: string) => {
28-
if (onAuthRequired) {
29-
onAuthRequired();
30-
return;
31-
}
32-
3324
if (setShowPicker) {
3425
setShowPicker(false);
3526
}
@@ -47,7 +38,7 @@ const ReactionsCounter = ({
4738
},
4839
});
4940
},
50-
[postId, setShowPicker, user, optimisticUpdate, onAuthRequired]
41+
[postId, setShowPicker, user, optimisticUpdate]
5142
);
5243

5344
return (
@@ -220,9 +211,7 @@ const ReactionsCounter = ({
220211

221212
export default function Reactions(props: any) {
222213
const { post } = props;
223-
const { visitor } = useVisitorAuth();
224214
const [showPicker, setShowPicker] = useState(false);
225-
const [isAuthModalOpen, setIsAuthModalOpen] = useState(false);
226215
const [reactions, setReactions] = useState<IReactions>({});
227216
const [userReaction, setUserReaction] = useState<IReactions>({});
228217

@@ -269,20 +258,12 @@ export default function Reactions(props: any) {
269258
updateReactions();
270259
}, [updateReactions]);
271260

272-
const handleReactionClick = useCallback(() => {
273-
if (!visitor) {
274-
setIsAuthModalOpen(true);
275-
return;
276-
}
277-
setShowPicker((v) => !v);
278-
}, [visitor]);
279-
280261
return (
281262
<div className="flex">
282263
<div className="relative flex items-center">
283264
<button
284265
className="text-sm p-1.5 my-2 border border-gray-300 dark:border-gray-700 rounded-full bg-white dark:bg-gray-800 text-gray-500 hover:text-gray-700 dark:text-gray-300 dark:hover:text-gray-200"
285-
onClick={handleReactionClick}
266+
onClick={() => setShowPicker((v) => !v)}
286267
>
287268
<svg
288269
className=" w-4 h-4"
@@ -332,15 +313,9 @@ export default function Reactions(props: any) {
332313
user={userReaction}
333314
optimisticUpdate={optimisticUpdate}
334315
setShowPicker={setShowPicker}
335-
onAuthRequired={!visitor ? () => setIsAuthModalOpen(true) : undefined}
336316
floating={false}
337317
/>
338318
) : null}
339-
340-
<VisitorAuthModal
341-
isOpen={isAuthModalOpen}
342-
onClose={() => setIsAuthModalOpen(false)}
343-
/>
344319
</div>
345320
);
346321
}

apps/page/pages/_sites/[site]/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export default function Index({
138138
</div>
139139
</main>
140140

141-
<Footer settings={settings} />
141+
<Footer settings={settings} roadmaps={roadmaps} />
142142
</div>
143143
</>
144144
);

apps/page/pages/_sites/[site]/roadmap/[roadmap_slug].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ export default function RoadmapPage({
327327
</div>
328328
</main>
329329

330-
<Footer settings={settings} />
330+
<Footer settings={settings} roadmaps={roadmaps} />
331331
</div>
332332

333333
{/* Item Details Modal */}

apps/page/pages/api/notifications/subscribe-email.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import inngestClient from "../../../utils/inngest";
1010

1111
async function handler(
1212
req: NextApiRequest,
13-
res: NextApiResponse<{ ok: boolean; message?: string } | null>
13+
res: NextApiResponse<{ success: boolean; message?: string } | null>
1414
) {
1515
if (req.method === "POST") {
1616
const hostname = String(req?.headers?.host);
1717
const { email } = req.body;
1818

1919
if (!email) {
20-
res.status(400).json({ ok: false });
20+
res.status(400).json({ success: false });
2121
return;
2222
}
2323

@@ -53,9 +53,10 @@ async function handler(
5353
email,
5454
decision.reason
5555
);
56-
return res
57-
.status(400)
58-
.json({ ok: false, message: "Please provide a valid email address" });
56+
return res.status(400).json({
57+
success: false,
58+
message: "Please provide a valid email address",
59+
});
5960
}
6061
}
6162

@@ -72,7 +73,7 @@ async function handler(
7273
const pageUrl = getPageUrl(page, settings);
7374

7475
if (!settings.email_notifications) {
75-
return res.status(400).json({ ok: false });
76+
return res.status(400).json({ success: false });
7677
}
7778

7879
const result = await subscribeViaEmail(String(page?.id), String(email));
@@ -100,10 +101,10 @@ async function handler(
100101
},
101102
});
102103

103-
res.status(200).json({ ok: true });
104+
res.status(200).json({ success: true });
104105
} catch (e: Error | any) {
105106
console.log("notifications/email: [Error]", e);
106-
res.status(400).json({ ok: false, message: e.message ?? String(e) });
107+
res.status(400).json({ success: false, message: e.message ?? String(e) });
107108
}
108109
} else {
109110
res.setHeader("Allow", "POST");

apps/page/pages/api/pa/view.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1+
import { supabaseAdmin } from "@changes-page/supabase/admin";
12
import type { NextApiRequest, NextApiResponse } from "next";
23
import UAParser from "ua-parser-js";
34
import { v4 } from "uuid";
45
import {
56
fetchRenderData,
67
translateHostToPageIdentifier,
78
} from "../../../lib/data";
8-
import { supabaseAdmin } from "@changes-page/supabase/admin";
99
import { getVisitorId } from "../../../lib/visitor-auth";
1010

1111
async function pageAnalyticsView(
1212
req: NextApiRequest,
13-
res: NextApiResponse<{ ok: boolean }>
13+
res: NextApiResponse<{ success: boolean }>
1414
) {
1515
if (String(req?.headers["user-agent"]).toLowerCase().includes("bot")) {
16-
return res.status(200).json({ ok: true });
16+
return res.status(200).json({ success: true });
1717
}
1818

1919
const hostname = String(req?.headers?.host);
@@ -51,10 +51,10 @@ async function pageAnalyticsView(
5151
console.error("pageAnalyticsView [Error]", error);
5252
}
5353

54-
res.status(200).json({ ok: true });
54+
res.status(200).json({ success: true });
5555
} catch (e: Error | any) {
5656
console.log("pageAnalyticsView [Error]", e);
57-
res.status(200).json({ ok: true });
57+
res.status(200).json({ success: true });
5858
}
5959
}
6060

apps/page/pages/api/post/react.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { supabaseAdmin } from "@changes-page/supabase/admin";
12
import type { NextApiRequest, NextApiResponse } from "next";
23
import { v4 } from "uuid";
3-
import { supabaseAdmin } from "@changes-page/supabase/admin";
44
import { getVisitorId } from "../../../lib/visitor-auth";
55

66
export default async function reactToPost(
77
req: NextApiRequest,
8-
res: NextApiResponse<{ ok: boolean }>
8+
res: NextApiResponse<{ success: boolean }>
99
) {
1010
const { post_id, reaction } = req.body;
1111

@@ -40,9 +40,9 @@ export default async function reactToPost(
4040
console.error("reactToPost [Error]", error);
4141
}
4242

43-
res.status(200).json({ ok: true });
43+
res.status(200).json({ success: true });
4444
} catch (e: Error | any) {
4545
console.log("reactToPost [Error]", e);
46-
res.status(200).json({ ok: true });
46+
res.status(200).json({ success: false });
4747
}
4848
}

apps/page/pages/api/post/reactions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { supabaseAdmin } from "@changes-page/supabase/admin";
12
import type { NextApiRequest, NextApiResponse } from "next";
23
import { v4 } from "uuid";
3-
import { supabaseAdmin } from "@changes-page/supabase/admin";
44

55
export default async function getPostReactions(
66
req: NextApiRequest,
7-
res: NextApiResponse<{ ok: boolean; aggregate: any; user: any }>
7+
res: NextApiResponse<{ success: boolean; aggregate: any; user: any }>
88
) {
99
let { post_id } = req.query;
1010
let { cp_pa_vid: visitor_id } = req.cookies;
@@ -41,7 +41,7 @@ export default async function getPostReactions(
4141
}
4242

4343
res.status(200).json({
44-
ok: true,
44+
success: true,
4545
aggregate: aggregate?.length
4646
? {
4747
thumbs_up: aggregate[0].thumbs_up_count,
@@ -55,6 +55,6 @@ export default async function getPostReactions(
5555
});
5656
} catch (e: Error | any) {
5757
console.log("getPostReactions [Error]", e);
58-
res.status(200).json({ ok: true, aggregate: null, user: null });
58+
res.status(200).json({ success: false, aggregate: null, user: null });
5959
}
6060
}

0 commit comments

Comments
 (0)