Skip to content

Commit

Permalink
-> need to make "editable" check and make possible to edit the event …
Browse files Browse the repository at this point in the history
…and update field
  • Loading branch information
Arakasi21 committed May 31, 2024
1 parent 31b02dc commit fe7a360
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/app/events/[eventID]/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ type FormData = {
end_date: string
location_uni: string
location_link: string
max_participants: string
// max_participants: string
cover_images: CoverImage[]
type: string
tags: string[]
[key: string]: string | CoverImage[] | string[]
}

export default function EditEventPage({ params }: { params: { eventID: string } }) {
Expand All @@ -63,7 +64,7 @@ export default function EditEventPage({ params }: { params: { eventID: string }
end_date: event?.end_date ? event.end_date : '',
location_uni: event?.location_university || '',
location_link: event?.location_link || '',
max_participants: event?.max_participants?.toString() || '',
// max_participants: event?.max_participants?.toString() || '',
cover_images: event?.cover_images || [],
type: event?.type || '',
tags: event?.tags || [],
Expand All @@ -80,6 +81,15 @@ export default function EditEventPage({ params }: { params: { eventID: string }
event.location_university &&
event.type

// const editableFields = [
// 'max_participants',
// 'location_link',
// 'location_university',
// 'start_date',
// 'end_date',
// 'is_hidden_for_non_members',
// ]

// ==================== ТУТ МЫ ПРОСТО ЗАДАЕМ EVENT STATUS ЦВЕТА ====================

const eventStatus = getEventStatus(event?.status || 'DRAFT')
Expand Down Expand Up @@ -280,13 +290,22 @@ export default function EditEventPage({ params }: { params: { eventID: string }
if (imageFile) {
uploadedImage = await handleImageUpload()
}
const updatedEvent = {
...formData,
cover_images: uploadedImage
? [uploadedImage].map((image, index) => ({ ...image, position: index + 1 }))
: [],
max_participants: parseInt(formData.max_participants),

const updatedEvent: Partial<FormData> = {}

for (const key in formData) {
if (event && formData[key] !== event[key]) {
updatedEvent[key] = formData[key]
}
}

if (uploadedImage) {
updatedEvent.cover_images = [uploadedImage].map((image, index) => ({
...image,
position: index + 1,
}))
}

await fetchEventInfo()
if (event) {
await updateEvent(event.id, updatedEvent)
Expand All @@ -306,7 +325,7 @@ export default function EditEventPage({ params }: { params: { eventID: string }
end_date: event.end_date ? event.end_date : '',
location_uni: event.location_university || '',
location_link: event.location_link || '',
max_participants: event.max_participants?.toString() || '',
// max_participants: event.max_participants?.toString() || '',
cover_images: event.cover_images || [],
type: event.type || '',
tags: event.tags || [],
Expand Down
1 change: 1 addition & 0 deletions src/types/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type Event = {
type: string
published_at: string
is_hidden_for_non_members: boolean
[key: string]: any
}

export type EventParticipationStatus = 'UNKNOWN' | 'BANNED' | 'PARTICIPANT'
Expand Down

0 comments on commit fe7a360

Please sign in to comment.