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

feat: add allocations ui mvp #4879

Merged
merged 1 commit into from
Apr 30, 2024
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
16 changes: 9 additions & 7 deletions apps/api/src/data/score-allocations.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
import { STATIC_IMAGES_URL } from '@hey/data/constants';

const allocations = [
{
description: 'Early Bloomer Guild Rold',
icon: 'https://hey.xyz/earlybloomer.png',
icon: `${STATIC_IMAGES_URL}/app-icon/0.png`,
id: 'EarlyBloomer',
name: 'Early Bloomer'
},
{
description: 'Gitcoin Grants Alpha Round',
icon: 'https://hey.xyz/gg-alpha.png',
icon: `${STATIC_IMAGES_URL}/brands/gitcoin.png`,
id: 'GGAlpha',
name: 'Gitcoin Grants Alpha Round'
},
{
description: 'Gitcoin Grants Beta Round',
icon: 'https://hey.xyz/gg-beta.png',
icon: `${STATIC_IMAGES_URL}/brands/gitcoin.png`,
id: 'GGBeta',
name: 'Gitcoin Grants Beta Round'
},
{
description: 'Gitcoin Round 14',
icon: 'https://hey.xyz/gg-14.png',
icon: `${STATIC_IMAGES_URL}/brands/gitcoin.png`,
id: 'GR14',
name: 'Gitcoin Round 14'
},
{
description: 'Gitcoin Round 15',
icon: 'https://hey.xyz/gg-15.png',
icon: `${STATIC_IMAGES_URL}/brands/gitcoin.png`,
id: 'GR15',
name: 'Gitcoin Round 15'
},
{
description: 'Gitcoin Grants Round 18',
icon: 'https://hey.xyz/gg-18.png',
icon: `${STATIC_IMAGES_URL}/brands/gitcoin.png`,
id: 'GG18',
name: 'Gitcoin Grants Round 18'
},
{
description: 'Gitcoin Grants Round 19',
icon: 'https://hey.xyz/gg-19.png',
icon: `${STATIC_IMAGES_URL}/brands/gitcoin.png`,
id: 'GG19',
name: 'Gitcoin Grants Round 19'
}
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/routes/score/allocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const get: Handler = async (req, res) => {

try {
const adjustedProfileScore = await prisma.adjustedProfileScore.findMany({
orderBy: { createdAt: 'desc' },
where: {
profileId: id as string,
reason: { in: allocations.map((allocation) => allocation.id) }
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Profile/Score.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Score: FC<ScoreProps> = ({ id }) => {
>
<button
className="font-mono text-xs font-bold"
onClick={() => setShowScoreModal(true, score.score)}
onClick={() => setShowScoreModal(true, score.score, id)}
>
{humanize(score.score)}
</button>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Shared/GlobalModals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const GlobalModals: FC = () => {
<OptimisticTransactions />
</Modal>
<Modal
onClose={() => setShowScoreModal(false, null)}
onClose={() => setShowScoreModal(false, null, null)}
show={showScoreModal}
size="xs"
title={`${APP_NAME} score`}
Expand Down
52 changes: 50 additions & 2 deletions apps/web/src/components/Shared/Modal/Score.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
import type { ScoreAllocation } from '@hey/types/hey';
import type { FC } from 'react';

import { APP_NAME, STATIC_IMAGES_URL } from '@hey/data/constants';
import { ArrowLongRightIcon } from '@heroicons/react/24/outline';
import { ArrowTrendingUpIcon } from '@heroicons/react/24/solid';
import { APP_NAME, HEY_API_URL, STATIC_IMAGES_URL } from '@hey/data/constants';
import humanize from '@hey/helpers/humanize';
import { useQuery } from '@tanstack/react-query';
import axios from 'axios';
import Link from 'next/link';
import { useGlobalModalStateStore } from 'src/store/non-persisted/useGlobalModalStateStore';

const Score: FC = () => {
const { score } = useGlobalModalStateStore();
const { score, scoreViewerProfileId } = useGlobalModalStateStore();
const renderScore =
score !== 0 ? (score ? humanize(score) : '...') : 'Not calculated yet';

const getAllocations = async (
profileId: null | string
): Promise<ScoreAllocation[]> => {
try {
const response = await axios.get(`${HEY_API_URL}/score/allocations`, {
params: { id: profileId }
});
return response.data.result;
} catch {
return [];
}
};

const { data } = useQuery({
enabled: Boolean(scoreViewerProfileId),
queryFn: () => getAllocations(scoreViewerProfileId),
queryKey: ['getAllocations', scoreViewerProfileId]
});

return (
<div className="flex flex-col items-center space-y-5 p-5">
<img
Expand Down Expand Up @@ -37,6 +61,30 @@ const Score: FC = () => {
Read more about {APP_NAME} score
</Link>
</div>
{(data || [])?.length > 0 ? (
<div className="space-y-2">
{data?.map((allocation) => (
<div
className="flex items-center space-x-2 text-sm"
key={allocation.id}
>
<div className="flex items-center space-x-1 font-bold text-green-500">
<ArrowTrendingUpIcon className="size-4" />
<div>{allocation.score}</div>
</div>
<ArrowLongRightIcon className="size-4" />
<div className="flex items-center space-x-2">
<img
alt={allocation.name}
className="h-4"
src={allocation.icon}
/>
<div>{allocation.name}</div>
</div>
</div>
))}
</div>
) : null}
</div>
);
};
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/components/Shared/Navbar/NavItems/Score.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import humanize from '@hey/helpers/humanize';
import cn from '@hey/ui/cn';
import { useGlobalModalStateStore } from 'src/store/non-persisted/useGlobalModalStateStore';
import { useScoreStore } from 'src/store/non-persisted/useScoreStore';
import { useProfileStore } from 'src/store/persisted/useProfileStore';

interface ScoreProps {
className?: string;
onClick?: () => void;
}

const Score: FC<ScoreProps> = ({ className = '', onClick }) => {
const { currentProfile } = useProfileStore();
const { score } = useScoreStore();
const { setShowScoreModal } = useGlobalModalStateStore();

Expand All @@ -22,7 +24,7 @@ const Score: FC<ScoreProps> = ({ className = '', onClick }) => {
className
)}
onClick={() => {
setShowScoreModal(true, score);
setShowScoreModal(true, score, currentProfile?.id);
onClick?.();
}}
type="button"
Expand Down
12 changes: 9 additions & 3 deletions apps/web/src/store/non-persisted/useGlobalModalStateStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface State {
reportingProfile: null | Profile;
reportingPublicationId: null | string;
score: null | number;
scoreViewerProfileId: null | string;
setShowAuthModal: (
showAuthModal: boolean,
authModalType?: AuthModalType
Expand All @@ -30,7 +31,11 @@ interface State {
reportProfileModal: boolean,
reportingProfile: null | Profile
) => void;
setShowScoreModal: (showScoreModal: boolean, score: null | number) => void;
setShowScoreModal: (
showScoreModal: boolean,
score: null | number,
scoreViewerProfileId: null | string
) => void;
showAuthModal: boolean;
showDiscardModal: boolean;
showInvitesModal: boolean;
Expand All @@ -48,6 +53,7 @@ const store = create<State>((set) => ({
reportingProfile: null,
reportingPublicationId: null,
score: null,
scoreViewerProfileId: null,
setShowAuthModal: (showAuthModal, authModalType) => {
set(() => ({ authModalType, showAuthModal }));
},
Expand All @@ -69,8 +75,8 @@ const store = create<State>((set) => ({
})),
setShowReportProfileModal: (showReportProfileModal, reportingProfile) =>
set(() => ({ reportingProfile, showReportProfileModal })),
setShowScoreModal: (showScoreModal, score) =>
set(() => ({ score, showScoreModal })),
setShowScoreModal: (showScoreModal, score, scoreViewerProfileId) =>
set(() => ({ score, scoreViewerProfileId, showScoreModal })),
showAuthModal: false,
showDiscardModal: false,
showInvitesModal: false,
Expand Down
8 changes: 8 additions & 0 deletions packages/types/hey.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,11 @@ export type Draft = {
id: string;
updatedAt: Date;
};

export type ScoreAllocation = {
description: string;
icon: string;
id: string;
name: string;
score: number;
};
Loading