Skip to content

Commit

Permalink
Merge pull request #745 from SuperteamDAO/feat/new-templates
Browse files Browse the repository at this point in the history
FEAT: New Templates
  • Loading branch information
JayeshVP24 authored Sep 18, 2024
2 parents 88542c6 + 084fc41 commit bc7a06b
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 93 deletions.
76 changes: 53 additions & 23 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,48 @@ model Bounties {
}

model BountiesTemplates {
id String @id @default(uuid())
title String?
slug String?
description String? @db.Text
color String?
emoji String?
isFeatured Boolean @default(false)
isActive Boolean @default(true)
isArchived Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
skills Json?
type BountyType @default(bounty)
Bounties Bounties[]
id String @id @default(uuid())
title String?
deadline DateTime?
slug String?
description String? @db.Text
color String?
emoji String?
isFeatured Boolean @default(false)
isActive Boolean @default(true)
isArchived Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
skills Json?
type BountyType @default(bounty)
requirements String? @db.Text
region Regions @default(GLOBAL)
applicationType ApplicationType @default(fixed)
status status @default(OPEN)
timeToComplete String?
token String?
references Json?
referredBy String?
publishedAt DateTime?
compensationType CompensationType @default(fixed)
maxRewardAsk Int?
minRewardAsk Int?
language String?
rewardAmount Float?
rewards Json?
maxBonusSpots Int @default(0)
usdValue Float?
sponsorId String
pocId String
pocSocials String?
source Source @default(NATIVE)
isPublished Boolean @default(false)
Bounties Bounties[]
sponsor Sponsors @relation(fields: [sponsorId], references: [id])
poc User @relation("poc", fields: [pocId], references: [id])
@@index([isActive, isArchived, type])
@@index([type])
}

model Comment {
Expand Down Expand Up @@ -231,24 +259,25 @@ model Submission {
}

model Sponsors {
id String @id @default(uuid())
name String @unique
slug String @unique
id String @id @default(uuid())
name String @unique
slug String @unique
logo String?
url String?
industry String
twitter String?
bio String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
isArchived Boolean @default(false)
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
isArchived Boolean @default(false)
isActive Boolean @default(true)
entityName String?
isVerified Boolean @default(false)
isCaution Boolean @default(false)
isVerified Boolean @default(false)
isCaution Boolean @default(false)
Hackathon Hackathon?
UserSponsors UserSponsors[]
Bounties Bounties[]
Templates BountiesTemplates[]
Grants Grants[]
User User[]
UserInvites UserInvites[]
Expand Down Expand Up @@ -327,6 +356,7 @@ model User {
currentSponsor Sponsors? @relation(fields: [currentSponsorId], references: [id])
UserSponsors UserSponsors[]
poc Bounties[] @relation("poc")
templates BountiesTemplates[] @relation("poc")
Comment Comment[]
Submission Submission[]
Grants Grants[]
Expand Down
4 changes: 3 additions & 1 deletion src/features/comments/components/Comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ interface Props {
isReply?: boolean;
addNewReply?: (msg: string) => Promise<void>;
isVerified?: boolean;
isTemplate?: boolean;
}

export const Comment = ({
Expand All @@ -72,6 +73,7 @@ export const Comment = ({
isReply = false,
isAnnounced,
isVerified = false,
isTemplate = false,
}: Props) => {
const { user } = useUser();
const posthog = usePostHog();
Expand Down Expand Up @@ -393,7 +395,7 @@ export const Comment = ({
_active={{
bg: 'brand.slate.400',
}}
isDisabled={!!newReplyLoading || !newReply}
isDisabled={!!newReplyLoading || !newReply || isTemplate}
isLoading={!!newReplyLoading}
loadingText="Adding..."
onClick={() => handleSubmit()}
Expand Down
5 changes: 4 additions & 1 deletion src/features/comments/components/Comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface Props {
isVerified?: boolean;
count: number;
setCount: Dispatch<SetStateAction<number>>;
isTemplate?: boolean;
}
export const Comments = ({
refId,
Expand All @@ -44,6 +45,7 @@ export const Comments = ({
listingSlug,
isAnnounced,
isVerified = false,
isTemplate = false,
count,
setCount,
}: Props) => {
Expand Down Expand Up @@ -240,7 +242,7 @@ export const Comments = ({
md: 'sm',
}}
fontWeight={500}
isDisabled={!!newCommentLoading || !newComment}
isDisabled={!!newCommentLoading || !newComment || isTemplate}
isLoading={!!newCommentLoading}
loadingText="Adding..."
onClick={() => handleSubmit()}
Expand Down Expand Up @@ -268,6 +270,7 @@ export const Comments = ({
refId={refId}
deleteComment={deleteComment}
isVerified={isVerified}
isTemplate={isTemplate}
/>
);
})}
Expand Down
30 changes: 19 additions & 11 deletions src/features/listings/components/ListingPage/ListingHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { SubscribeListing } from './SubscribeListing';

export function ListingHeader({
listing,
isTemplate,
isTemplate = false,
commentCount,
}: {
listing: Listing;
Expand Down Expand Up @@ -272,14 +272,14 @@ export function ListingHeader({
<ListingTitle />
</Flex>
</HStack>
{!isTemplate && (
<Flex display={{ base: 'none', md: 'flex' }}>
<HeaderSub />
</Flex>
)}
<Flex display={{ base: 'none', md: 'flex' }}>
<HeaderSub />
</Flex>
</VStack>
</HStack>
{!isTemplate && listing.id && <SubscribeListing id={listing.id} />}
{listing.id && (
<SubscribeListing isTemplate={isTemplate} id={listing.id} />
)}
</VStack>
<Flex
direction={'column'}
Expand All @@ -291,7 +291,7 @@ export function ListingHeader({
<ListingTitle />
<HeaderSub />
</Flex>
{!isTemplate && (
{
<Flex align={'center'} w={'full'} maxW="7xl" h={10}>
<HStack
align="center"
Expand All @@ -316,7 +316,11 @@ export function ListingHeader({
}}
/>
<ListingTabLink
href={`/listings/${type}/${slug}/`}
href={
!isTemplate
? `/listings/${type}/${slug}/`
: `/templates/listings/${slug}/`
}
text="Details"
isActive={
!router.asPath.split('/')[4]?.includes('submission') &&
Expand All @@ -339,7 +343,11 @@ export function ListingHeader({
{isProject && references && references?.length > 0 && (
<>
<ListingTabLink
href={`/listings/${type}/${slug}/references`}
href={
!isTemplate
? `/listings/${type}/${slug}/references`
: `/templates/listings/${slug}/references`
}
text="References"
isActive={
!!router.asPath.split('/')[4]?.includes('references')
Expand All @@ -349,7 +357,7 @@ export function ListingHeader({
)}
</HStack>
</Flex>
)}
}
</VStack>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ import { PrizesList } from './PrizesList';
export function RightSideBar({
listing,
skills,
isTemplate = false,
}: {
listing: Listing;
skills?: ParentSkills[];
isTemplate?: boolean;
}) {
const {
id,
Expand Down Expand Up @@ -300,7 +302,7 @@ export function RightSideBar({
<Text color={'#94A3B8'}>Time to Complete</Text>
</Flex>
)}
<SubmissionActionButton listing={listing} />
<SubmissionActionButton listing={listing} isTemplate={isTemplate} />
{isProject && deadline && dayjs(deadline).isAfter(new Date()) && (
<Flex gap="2" w="full" mt={-1} mb={4} p="3" bg={'#62F6FF10'}>
<WarningIcon color="#1A7F86" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ import { listingSubscriptionsQuery } from '../../queries/listing-notification-st

interface Props {
id: string;
isTemplate?: boolean;
}

const toggleSubscription = async (id: string) => {
await axios.post('/api/listings/notifications/toggle', { bountyId: id });
};

export const SubscribeListing = ({ id }: Props) => {
export const SubscribeListing = ({ id, isTemplate = false }: Props) => {
const { user } = useUser();
const posthog = usePostHog();
const queryClient = useQueryClient();
Expand Down Expand Up @@ -91,6 +92,7 @@ export const SubscribeListing = ({ id }: Props) => {
fontWeight={500}
borderColor="brand.slate.300"
aria-label="Notify"
isDisabled={isTemplate}
onClick={() => {
posthog.capture(
sub.find((e) => e.userId === user?.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ import { SubmissionModal } from './SubmissionModal';

interface Props {
listing: Listing;
isTemplate?: boolean;
}

export const SubmissionActionButton = ({ listing }: Props) => {
export const SubmissionActionButton = ({
listing,
isTemplate = false,
}: Props) => {
const {
id,
status,
Expand Down Expand Up @@ -158,6 +162,7 @@ export const SubmissionActionButton = ({ listing }: Props) => {
isOpen={isOpen}
editMode={buttonState === 'edit'}
listing={listing}
isTemplate={isTemplate}
showEasterEgg={() => setEasterEggOpen(true)}
onSurveyOpen={onSurveyOpen}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface Props {
onClose: () => void;
editMode: boolean;
listing: Listing;
isTemplate?: boolean;
showEasterEgg: () => void;
onSurveyOpen: () => void;
}
Expand All @@ -62,6 +63,7 @@ export const SubmissionModal = ({
onClose,
editMode,
listing,
isTemplate = false,
showEasterEgg,
onSurveyOpen,
}: Props) => {
Expand Down Expand Up @@ -521,6 +523,7 @@ export const SubmissionModal = ({
<Button
className="ph-no-capture"
w={'full'}
isDisabled={isTemplate}
isLoading={!!isLoading}
loadingText="Submitting..."
type="submit"
Expand Down
5 changes: 5 additions & 0 deletions src/layouts/Listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ interface ListingPageProps {
bounty: Listing | null;
children: React.ReactNode;
maxW?: ChakraProps['maxW'];
isTemplate?: boolean;
}

export function ListingPageLayout({
bounty: initialBounty,
children,
maxW = '7xl',
isTemplate = false,
}: ListingPageProps) {
const [, setBountySnackbar] = useAtom(bountySnackbarAtom);
const posthog = usePostHog();
Expand Down Expand Up @@ -152,6 +154,7 @@ export function ListingPageLayout({
<Box w="100%" mx="auto" px={{ base: '2', lg: 6 }}>
<Box w="100%" maxW={'7xl'} mx="auto">
<ListingHeader
isTemplate={isTemplate}
commentCount={commentCount}
listing={initialBounty}
/>
Expand All @@ -172,6 +175,7 @@ export function ListingPageLayout({
h="full"
>
<RightSideBar
isTemplate={isTemplate}
listing={initialBounty}
skills={iterableSkills}
/>
Expand Down Expand Up @@ -259,6 +263,7 @@ export function ListingPageLayout({
)}

<Comments
isTemplate={isTemplate}
isAnnounced={initialBounty?.isWinnersAnnounced ?? false}
listingSlug={initialBounty?.slug ?? ''}
listingType={initialBounty?.type ?? ''}
Expand Down
8 changes: 8 additions & 0 deletions src/pages/api/listings/templates/[slug].ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';

import logger from '@/lib/logger';
import { prisma } from '@/prisma';
import { dayjs } from '@/utils/dayjs';
import { safeStringify } from '@/utils/safeStringify';

export default async function user(req: NextApiRequest, res: NextApiResponse) {
Expand All @@ -17,6 +18,10 @@ export default async function user(req: NextApiRequest, res: NextApiResponse) {
slug,
isActive: true,
},
include: {
poc: true,
sponsor: true,
},
});

if (!result) {
Expand All @@ -26,6 +31,9 @@ export default async function user(req: NextApiRequest, res: NextApiResponse) {
});
}

// set deadline dynamically
result.deadline = dayjs(new Date()).add(6, 'days').toDate();

logger.info(`Successfully fetched bounty template for slug: ${slug}`);
return res.status(200).json(result);
} catch (error: any) {
Expand Down
Loading

0 comments on commit bc7a06b

Please sign in to comment.