Skip to content

Commit

Permalink
Fix editing event date values
Browse files Browse the repository at this point in the history
(cherry picked from commit 8f01ee2)
  • Loading branch information
lil5 committed Jan 3, 2024
1 parent 70f1ccb commit 84f2936
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
23 changes: 16 additions & 7 deletions frontend/src/components/EventChangeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,20 @@ export default function EventChangeForm(props: {
initialValues?: EventCreateBody;
onSubmit: (v: EventCreateBody) => void;
}) {
const { t } = useTranslation();
const { authUser } = useContext(AuthContext);
const { addToastError } = useContext(ToastContext);
const refFileInput = useRef<HTMLInputElement>(null);

const [values, setValue, setValues] = useForm<EventCreateBody>(
props.initialValues || defaultValues
);
const sepDate = useSepDateTime(values.date, (d) => setValue("date", d));
const [hasEndDate, setHasEndDate] = useState(values.date_end !== null);
const [firstSetDefaultEndDate, setFirstSetDefaultEndDate] = useState(false);
const [dateEnd, setDateEnd] = useState(
values.date_end || dayjs().add(2, "hour").minute(0).second(0).format()
values.date_end ||
dayjs(values.date).add(2, "hour").minute(0).second(0).format()
);
const sepDateEnd = useSepDateTime(dateEnd, setDateEnd);
const [deleteImageUrl, setDeleteImageUrl] = useState("");
Expand All @@ -119,7 +122,13 @@ export default function EventChangeForm(props: {
const [eventPriceCurrency, _setEventPriceCurrency] = useState(
() => values.price_currency || ""
);
const { t } = useTranslation();
const [chains, setChains] = useState<Chain[]>([]);

useEffect(() => {
getChains();
}, []);

useEffect(() => {}, [props.initialValues]);

function setEventPriceCurrency(e: ChangeEvent<HTMLSelectElement>) {
const v = e.target.value;
Expand Down Expand Up @@ -170,11 +179,6 @@ export default function EventChangeForm(props: {
props.onSubmit(values);
}

const [chains, setChains] = useState<Chain[]>([]);
useEffect(() => {
getChains();
}, []);

async function getChains() {
if (!authUser) return;
let chainUIDs = authUser.chains
Expand All @@ -194,6 +198,11 @@ export default function EventChangeForm(props: {

const isValidPrice = validatePrice(eventPriceText);

console.log("initial values: ", props.initialValues);
console.log("Date values: ", values.date);
console.log("Date End values: ", values.date_end);
console.log("Date End calc: ", dateEnd);

return (
<div className="w-full">
<form onSubmit={submit} className="grid gap-x-4 sm:grid-cols-2">
Expand Down
12 changes: 8 additions & 4 deletions server/internal/controllers/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func EventCreate(c *gin.Context) {
Address: body.Address,
Link: body.Link,
Date: body.Date,
DateEnd: body.DateEnd,
Genders: body.Genders,
UserID: user.ID,
ImageUrl: body.ImageUrl,
Expand Down Expand Up @@ -238,7 +239,7 @@ func EventUpdate(c *gin.Context) {
Latitude *float64 `json:"latitude,omitempty" binding:"omitempty,latitude"`
Longitude *float64 `json:"longitude,omitempty" binding:"omitempty,longitude"`
Date *time.Time `json:"date,omitempty"`
DateEnd *null.Time `json:"date_end,omitempty"`
DateEnd *time.Time `json:"date_end,omitempty"`
Genders *[]string `json:"genders,omitempty"`
ImageUrl *string `json:"image_url,omitempty"`
ImageDeleteUrl *string `json:"image_delete_url,omitempty"`
Expand Down Expand Up @@ -304,9 +305,12 @@ func EventUpdate(c *gin.Context) {
}
if body.Date != nil {
event.Date = *(body.Date)
}
if body.DateEnd != nil {
event.DateEnd = *(body.DateEnd)
// Must set the start date to set the end date
if body.DateEnd != nil {
event.DateEnd = null.Time{Time: *(body.DateEnd), Valid: true}
} else {
event.DateEnd = null.Time{}
}
}
if body.Genders != nil {
event.Genders = *(body.Genders)
Expand Down

0 comments on commit 84f2936

Please sign in to comment.