Skip to content

Commit

Permalink
fix: avoid adding reminder for past events
Browse files Browse the repository at this point in the history
  • Loading branch information
jeferson-sb committed Nov 26, 2023
1 parent a6c313c commit 2422146
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/pages/year.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useMemo, useState } from 'react'
import { type NextPage } from 'next'
import Link from 'next/link'
import dayjs from 'dayjs'

import styles from './year.module.css'

Expand Down Expand Up @@ -44,11 +45,21 @@ const FeedYear: NextPage = () => {
const handleSubscribe = useCallback(async (event: Conference.Type) => {
try {
const currentUser = session?.user
const isPast = dayjs().isAfter(event.endDate)

if (!currentUser || !isAuthenticated) {
return setSubscribeDialog(true)
}

if (isPast) {
showToast({
type: 'error',
title: 'You cannot subscribe to a past conference',
placement: 'bottom-right',
})
return
}

const userId = currentUser?.id

const existingReminder = await api.reminder.getByEvent.fetch({
Expand Down
4 changes: 2 additions & 2 deletions src/view/components/conf/CreateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import * as Category from '../../../domain/Category'
type CreateFormProps = {
onSubmit: (SubmitHandler: CreateFormState) => void
categories: Category.Type[]
isLoading: boolean
isLoading?: boolean
}

const CreateForm = ({ onSubmit, categories, isLoading }: CreateFormProps) => {
const CreateForm = ({ onSubmit, categories, isLoading = false }: CreateFormProps) => {
const { register, handleSubmit, watch, formState } = useForm<CreateFormState>(
{
resolver: zodResolver(creationValidationSchema),
Expand Down

0 comments on commit 2422146

Please sign in to comment.