Skip to content

Commit

Permalink
feat: version 1 finalized
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonCrk committed Nov 26, 2023
1 parent 384fda5 commit 3a4966f
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 60 deletions.
4 changes: 2 additions & 2 deletions src/components/ConnectionItem.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const ConnectionItem: FC<Connection> = ({ id, user }) => {
mutate: mutateRemoveConnection,
} = useMutation({
mutationFn: removeConnection,
onSuccess: ({ message }) => {
queryClient.invalidateQueries({ queryKey: ['network'] })
onSuccess: async ({ message }) => {
await queryClient.invalidateQueries({ queryKey: ['network'] })
showAlert({
message,
type: 'success',
Expand Down
4 changes: 2 additions & 2 deletions src/components/EditProfileModal.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const EditProfileModal: FC<Props> = ({ accountId, accountAbout }) => {

const { isPending, mutate: mutateEditProfile } = useMutation({
mutationFn: updateProfile,
onSuccess: ({ message }) => {
queryClient.invalidateQueries({ queryKey: ['profile', accountId] })
onSuccess: async ({ message }) => {
await queryClient.invalidateQueries({ queryKey: ['profile', accountId] })
showAlert({
message,
type: 'success',
Expand Down
8 changes: 4 additions & 4 deletions src/components/EventCard.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ const EventCard: FC<Props> = ({
const queryClient = useQueryClient()
const { showAlert } = useAlerts()

const handleCancelEvent = () => {
queryClient.invalidateQueries({ queryKey: ['home'] })
const handleCancelEvent = async () => {
await queryClient.invalidateQueries({ queryKey: ['home'] })
}

const handleDeleteEvent = (message: string) => {
queryClient.invalidateQueries({ queryKey: ['home'] })
const handleDeleteEvent = async (message: string) => {
await queryClient.invalidateQueries({ queryKey: ['home'] })
showAlert({
message,
type: 'success',
Expand Down
7 changes: 4 additions & 3 deletions src/components/Input.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ const Input: FC<Props> = ({
className={`form-control ${fullWidth && 'w-100'} mb-1 ${
isError && 'is-invalid'
}`}
{...props}
{...register(name, {
setValueAs: value => {
if (props.type === 'number') return parseInt(value)
if (props.type === 'datetime-local' && value)
return new Date(value).toISOString()
// if (props.type === 'datetime-local') {
// return new Date(value).toISOString()
// }
return value
},
})}
{...props}
/>
</div>
{isError && <p className='text-danger mb-0'>{errorMessage}</p>}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Select.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const Select: FC<Props> = ({
{label}
</label>
)}

<select
id={id}
className={`form-select ${isError && 'is-invalid'}`}
Expand All @@ -44,6 +45,7 @@ const Select: FC<Props> = ({
<option value={''}>{defaultOption}</option>
{!isLoading && options()}
</select>

{isError && <p className='text-danger mb-0'>{errorMessage}</p>}
</div>
)
Expand Down
35 changes: 22 additions & 13 deletions src/components/SelectCategory.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ const SelectCategory: FC<Props> = ({
refetchOnMount: false,
})

if (isLoading)
return (
<>
<label className='form-label'>
Categorías
<select className='form-select'>
<option value={''}>Cargando...</option>
</select>
</label>
</>
)

return (
<Select
id='selectCategory'
Expand All @@ -44,19 +56,16 @@ const SelectCategory: FC<Props> = ({
isError={isError}
options={() => (
<>
{categories?.data.map(category => (
<option
key={category.id}
value={isIdValue ? category.id : category.name}
selected={
isIdValue
? selectProps.defaultValue === category.id
: selectProps.defaultValue === category.name
}
>
{category.name}
</option>
))}
{!isLoading &&
categories &&
categories.data.map(category => (
<option
key={category.id}
value={isIdValue ? category.id : category.name}
>
{category.name}
</option>
))}
</>
)}
{...selectProps}
Expand Down
4 changes: 2 additions & 2 deletions src/models/category.model.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export interface Category {
id: string
name: string
picture: string
icon: string
}

export type CategoryId = Category['id']
export type CategoryName = Category['name']
export type CategoryPicture = Category['picture']
export type CategoryPicture = Category['icon']
14 changes: 7 additions & 7 deletions src/models/event.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ export interface EventDetails extends Event {
}

export interface UpdateEvent {
name?: EventName
description?: EventDescription
category?: CategoryId
local?: EventLocal
visibility?: EventVisibility
realizationDate?: EventRealizationDate
finishDate?: EventFinishDate
name: EventName
description: EventDescription
category: CategoryId
local: EventLocal
visibility: EventVisibility
realizationDate: EventRealizationDate
finishDate: EventFinishDate
}

export interface SearchEventsParticipatingParams {
Expand Down
2 changes: 2 additions & 0 deletions src/pages/CreateEvent.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ function CreateEvent() {
<Input
label='Realization date'
name='realizationDate'
min={new Date().toUTCString()}
register={register}
type='datetime-local'
errorMessage={errors.realizationDate?.message}
Expand All @@ -138,6 +139,7 @@ function CreateEvent() {
<Input
label='Finish date'
name='finishDate'
min={new Date().toUTCString()}
type='datetime-local'
register={register}
errorMessage={errors.finishDate?.message}
Expand Down
16 changes: 8 additions & 8 deletions src/pages/EditEvent.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ function EditEvent() {

const navigate = useNavigate()

const { data: event, isLoading: isLoadingEvent } = useQuery({
queryKey: ['eventDetails', eventId],
queryFn: () => getEventById(eventId!),
refetchOnWindowFocus: false,
enabled: !!eventId && eventId !== undefined,
})

const {
handleSubmit,
register,
Expand All @@ -37,14 +44,7 @@ function EditEvent() {
resolver: zodResolver(updateEventSchemaValidation),
})

const { data: event, isLoading: isLoadingEvent } = useQuery({
queryKey: ['eventDetails', eventId],
queryFn: () => getEventById(eventId!),
refetchOnWindowFocus: false,
enabled: eventId !== undefined,
})

const { mutate: mutateUpdateEvent, isPending: isPendingUpdateEvent } =
const { isPending: isPendingUpdateEvent, mutate: mutateUpdateEvent } =
useMutation({
mutationFn: updateEvent,
onSuccess: ({ message }) => {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/EventDetails.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function EventDetails() {
const { isLoading, data: event } = useQuery({
queryKey: ['eventDetails', eventId],
queryFn: () => getEventById(eventId!),
enabled: !!eventId && eventId != undefined,
refetchOnWindowFocus: false,
})

Expand Down Expand Up @@ -149,7 +150,7 @@ function EventDetails() {
<div className='d-flex flex-wrap gap-2 mb-3'>
<Tag
color='primary'
icon={event.category.picture}
icon={event.category.icon}
name={event.category.name}
/>

Expand Down
12 changes: 8 additions & 4 deletions src/pages/UserProfile.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ function UserProfile() {
const { mutate: mutateUpdateProfile, isPending: isPendingUpdateAccount } =
useMutation({
mutationFn: updateProfile,
onSuccess: ({ message }) => {
queryClient.invalidateQueries({ queryKey: ['profile', accountId] })
onSuccess: async ({ message }) => {
await queryClient.invalidateQueries({
queryKey: ['profile', accountId],
})
showAlert({
message,
type: 'success',
Expand All @@ -54,8 +56,10 @@ function UserProfile() {
const { mutate: mutateSendInvitation, isPending: isPendingSendInvitation } =
useMutation({
mutationFn: sendInvitation,
onSuccess: ({ message }) => {
queryClient.invalidateQueries({ queryKey: ['profile', accountId] })
onSuccess: async ({ message }) => {
await queryClient.invalidateQueries({
queryKey: ['profile', accountId],
})
showAlert({
message,
type: 'success',
Expand Down
22 changes: 8 additions & 14 deletions src/validations/event.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,13 @@ export const createEventSchemaValidation = z
invalid_type_error: 'Must be a datetime',
required_error: 'The realization date is required',
})
.datetime({ message: 'Invalid realization date' })
.refine(realizationDate => new Date(realizationDate) > new Date(), {
message: 'The realization date must be a greater than the current date',
}),
finishDate: z
.string({
invalid_type_error: 'Must be a datetime',
required_error: 'The finish date is required',
})
.datetime({ message: 'Invalid finish date' }),
finishDate: z.string({
invalid_type_error: 'Must be a datetime',
required_error: 'The finish date is required',
}),
})
.refine(
({ realizationDate, finishDate }) =>
Expand Down Expand Up @@ -103,16 +100,13 @@ export const updateEventSchemaValidation = z
invalid_type_error: 'Must be a datetime',
required_error: 'The realization date is required',
})
.datetime({ message: 'Invalid realization date' })
.refine(realizationDate => new Date(realizationDate) > new Date(), {
message: 'The realization date must be a greater than the current date',
}),
finishDate: z
.string({
invalid_type_error: 'Must be a datetime',
required_error: 'The finish date is required',
})
.datetime({ message: 'Invalid finish date' }),
finishDate: z.string({
invalid_type_error: 'Must be a datetime',
required_error: 'The finish date is required',
}),
})
.refine(
({ realizationDate, finishDate }) =>
Expand Down

0 comments on commit 3a4966f

Please sign in to comment.