The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
make startsAt optional
Kiran Kffb614ab8d40
diff --git a/apps/web/app/(ee)/api/bounties/route.ts b/apps/web/app/(ee)/api/bounties/route.tsindex 9422573f2b..96448276b6 100644--- a/apps/web/app/(ee)/api/bounties/route.ts+++ b/apps/web/app/(ee)/api/bounties/route.ts@@ -105,7 +105,7 @@ export const POST = withWorkspace(async ({ workspace, req, session }) => {const programId = getDefaultProgramIdOrThrow(workspace);- const {+ let {name,description,type,@@ -120,7 +120,10 @@ export const POST = withWorkspace(performanceScope,} = createBountySchema.parse(await parseRequestBody(req));- if (startsAt && endsAt && endsAt < startsAt) {+ // Use current date as default if startsAt is not provided+ startsAt = startsAt || new Date();++ if (endsAt && endsAt < startsAt) {throw new DubApiError({message:"Bounty end date (endsAt) must be on or after start date (startsAt).",@@ -129,7 +132,7 @@ export const POST = withWorkspace(}if (submissionsOpenAt) {- if (startsAt && submissionsOpenAt < startsAt) {+ if (submissionsOpenAt < startsAt) {throw new DubApiError({message:"Bounty submissions open date (submissionsOpenAt) must be on or after start date (startsAt).",diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsxindex 1189851751..b84c66b99a 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx@@ -92,6 +92,7 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {const { id: workspaceId } = useWorkspace();const { makeRequest, isSubmitting } = useApiMutation<BountyProps>();+ const [hasStartDate, setHasStartDate] = useState(!!bounty?.startsAt);const [hasEndDate, setHasEndDate] = useState(!!bounty?.endsAt);const [openAccordions, setOpenAccordions] = useState(ACCORDION_ITEMS);const [submissionWindow, setSubmissionWindow] = useState<number | null>(null);@@ -189,6 +190,13 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {);}, [bounty?.submissionsOpenAt]);+ // Make sure startsAt is null if hasStartDate is false+ useEffect(() => {+ if (!hasStartDate) {+ setValue("startsAt", null);+ }+ }, [hasStartDate, setValue]);+// Make sure endsAt is null if hasEndDate is falseuseEffect(() => {if (!hasEndDate) {@@ -243,11 +251,7 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {// Decide if the submit button should be disabledconst shouldDisableSubmit = useMemo(() => {- if (!startsAt) {- return true;- }-- if (endsAt && endsAt <= startsAt) {+ if (startsAt && endsAt && endsAt <= startsAt) {return true;}@@ -420,23 +424,47 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {Set the schedule, reward, and additional details.</p>- <div>- <Controller- control={control}- name="startsAt"- render={({ field }) => (- <SmartDateTimePicker- value={field.value}- onChange={(date) =>- field.onChange(date ?? undefined)- }- label="Start date"- placeholder='E.g. "2024-03-01", "Last Thursday", "2 hours ago"'+ <AnimatedSizeContainer+ height+ transition={{ ease: "easeInOut", duration: 0.2 }}+ className={!hasStartDate ? "hidden" : ""}+ style={{ display: !hasStartDate ? "none" : "block" }}+ >+ <div className="flex items-center gap-4">+ <Switch+ fn={setHasStartDate}+ checked={hasStartDate}+ trackDimensions="w-8 h-4"+ thumbDimensions="w-3 h-3"+ thumbTranslate="translate-x-4"+ disabled={Boolean(bounty?.startsAt)}+ />+ <div className="flex flex-col gap-1">+ <h3 className="text-sm font-medium text-neutral-700">+ Start date+ </h3>+ </div>+ </div>++ {hasStartDate && (+ <div className="mt-3 p-px">+ <Controller+ control={control}+ name="startsAt"+ render={({ field }) => (+ <SmartDateTimePicker+ value={field.value}+ onChange={(date) =>+ field.onChange(date ?? undefined)+ }+ placeholder='E.g. "2024-03-01", "Last Thursday", "2 hours ago"'+ />+ )}/>- )}- />- {errors.startsAt && "test"}- </div>+ {errors.startsAt && "test"}+ </div>+ )}+ </AnimatedSizeContainer><AnimatedSizeContainerheight@@ -460,7 +488,7 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {</div>{hasEndDate && (- <div className="mt-6 p-px">+ <div className="mt-3 p-px"><Controllercontrol={control}name="endsAt"@@ -470,7 +498,6 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {onChange={(date) =>field.onChange(date ?? undefined)}- label="End date"placeholder='E.g. "in 3 months"'/>)}@@ -507,7 +534,7 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {</div>{submissionWindow && (- <div className="mt-6 p-px">+ <div className="mt-3 p-px"><NumberSteppervalue={submissionWindow}onChange={(v) => setSubmissionWindow(v)}diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.tsindex 8a74fe291b..5882d3f3dc 100644--- a/apps/web/lib/zod/schemas/bounties.ts+++ b/apps/web/lib/zod/schemas/bounties.ts@@ -52,7 +52,7 @@ export const createBountySchema = z.object({.max(500, "Description must be less than 500 characters").nullish(),type: z.nativeEnum(BountyType),- startsAt: parseDateSchema,+ startsAt: parseDateSchema.nullish(),endsAt: parseDateSchema.nullish(),submissionsOpenAt: parseDateSchema.nullish(),rewardAmount: z