From aa89a724c54ed0220c62e5d5157922a9a2265e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Palma?= Date: Wed, 7 Feb 2024 15:44:41 +0000 Subject: [PATCH] fix: publishStartDate on quickEditOfferForm is now correct one --- .../Manage/CompanyOffersManagementWidget.js | 53 +++++------ .../Offers/Manage/QuickOfferEditForm.js | 7 +- .../PublicationEndDateComponent.js | 88 ++++++++++--------- src/hooks/useOfferForm.js | 5 +- 4 files changed, 81 insertions(+), 72 deletions(-) diff --git a/src/components/Company/Offers/Manage/CompanyOffersManagementWidget.js b/src/components/Company/Offers/Manage/CompanyOffersManagementWidget.js index ada3e9ca..9568687e 100644 --- a/src/components/Company/Offers/Manage/CompanyOffersManagementWidget.js +++ b/src/components/Company/Offers/Manage/CompanyOffersManagementWidget.js @@ -31,27 +31,29 @@ import CollapsedQuickOfferEdit from "./CollapsedQuickOfferEdit"; const generateRow = ({ title, location, publishDate, publishEndDate, isHidden, isArchived, hiddenReason, ownerName, getOfferVisibility, setOfferVisibility, offerId, _id, ...args }) => ({ - fields: { - title: { value: ( - ), align: "left", linkDestination: `/offer/${_id}` }, - publishStartDate: { value: format(parseISO(publishDate), "yyyy-MM-dd") }, - publishEndDate: { value: format(parseISO(publishEndDate), "yyyy-MM-dd") }, - location: { value: location }, - }, - payload: { - offer: new Offer({ - title, location, publishDate, publishEndDate, isHidden, - isArchived, hiddenReason, ownerName, _id, ...args, - }), - getOfferVisibility: getOfferVisibility, - setOfferVisibility: setOfferVisibility, - offerId: offerId, - }, -}); + fields: { + title: { + value: ( + ), align: "left", linkDestination: `/offer/${_id}` + }, + publishStartDate: { value: format(parseISO(publishDate), "yyyy-MM-dd") }, + publishEndDate: { value: format(parseISO(publishEndDate), "yyyy-MM-dd") }, + location: { value: location }, + }, + payload: { + offer: new Offer({ + title, location, publishDate, publishEndDate, isHidden, + isArchived, hiddenReason, ownerName, _id, ...args, + }), + getOfferVisibility: getOfferVisibility, + setOfferVisibility: setOfferVisibility, + offerId: offerId, + }, + }); const sorters = { title: alphabeticalSorter, @@ -198,8 +200,7 @@ const CompanyOffersManagementWidget = ({ addSnackbar, isMobile }) => { return !isMobile ? ( ) : ( <> @@ -207,7 +208,7 @@ const CompanyOffersManagementWidget = ({ addSnackbar, isMobile }) => { - Actions + Actions @@ -269,8 +270,8 @@ const CompanyOffersManagementWidget = ({ addSnackbar, isMobile }) => { emptyMessage="No offers here." RowContent={RowContent} RowCollapseComponent={RowCollapseComponent} - handleSelect={() => {}} - handleSelectAll={() => {}} + handleSelect={() => { }} + handleSelectAll={() => { }} isSelectableTable={false} isLoading={isLoading} error={error} diff --git a/src/components/Company/Offers/Manage/QuickOfferEditForm.js b/src/components/Company/Offers/Manage/QuickOfferEditForm.js index 20c958d3..0bf54824 100644 --- a/src/components/Company/Offers/Manage/QuickOfferEditForm.js +++ b/src/components/Company/Offers/Manage/QuickOfferEditForm.js @@ -18,10 +18,13 @@ export const QuickOfferEditForm = ({ offerId, showTitle = false }) => { dispatch(addSnackbar(notification)); }; - const { publishEndDate } = offers[offerId]["fields"]; + const { publishStartDate, publishEndDate } = offers[offerId]["fields"]; + + console.log("Publish start date is: ", publishStartDate); const { control, fields, errors } = useOfferForm(EditOfferSchema, { publishEndDate: publishEndDate.value, + publishDate: publishStartDate.value }); const isObjectEmpty = @@ -62,6 +65,8 @@ export const QuickOfferEditForm = ({ offerId, showTitle = false }) => { } }; + console.log("Errors are: ", errors); + return (
onSubmit(e)} aria-label="Quick Offer Edit Form"> {showTitle && Quick Edit Offer} diff --git a/src/components/Offers/Form/form-components/PublicationEndDateComponent.js b/src/components/Offers/Form/form-components/PublicationEndDateComponent.js index 20187e33..911a58d3 100644 --- a/src/components/Offers/Form/form-components/PublicationEndDateComponent.js +++ b/src/components/Offers/Form/form-components/PublicationEndDateComponent.js @@ -7,52 +7,54 @@ import { Info } from "@material-ui/icons"; const PublicationEndDateComponent = ({ fields, disabled, errors, requestErrors, control, datePickerProps, showInfoTooltip = true, -}) => ( - <> - ( - { - const date = new Date(value); - // KeybaordDatePicker defaults its date to midnight. It makes more sense to consider the last hour of the day - // The offer is available between day x (00:00) and day y (23:59) - date.setHours(23, 59, 59, 0); - onChange(date); - }} - onBlur={onBlur} - variant="inline" - autoOk - format="yyyy-MM-dd" - minDate={fields?.publishDate} - error={!!errors?.publishEndDate || +}) => { + return ( + <> + ( + { + const date = new Date(value); + // KeybaordDatePicker defaults its date to midnight. It makes more sense to consider the last hour of the day + // The offer is available between day x (00:00) and day y (23:59) + date.setHours(23, 59, 59, 0); + onChange(date); + }} + onBlur={onBlur} + variant="inline" + autoOk + format="yyyy-MM-dd" + minDate={fields?.publishDate} + error={!!errors?.publishEndDate || !!requestErrors?.publishEndDate} - helperText={errors?.publishEndDate?.message || + helperText={errors?.publishEndDate?.message || requestErrors?.publishEndDate?.message || " "} - {...datePickerProps} - />)} - control={control} - /> - {showInfoTooltip ? - - - + {...datePickerProps} + />)} + control={control} + /> + {showInfoTooltip ? + + + - : "" - } - -); + : "" + } + + ) +}; PublicationEndDateComponent.propTypes = { fields: PropTypes.object.isRequired, diff --git a/src/hooks/useOfferForm.js b/src/hooks/useOfferForm.js index e2d4f173..5bad14cc 100644 --- a/src/hooks/useOfferForm.js +++ b/src/hooks/useOfferForm.js @@ -8,13 +8,14 @@ import { INITIAL_JOB_DURATION } from "../reducers/searchOffersReducer"; import useSession from "./useSession"; export default (schema, overrideDefaultValues) => { + console.log("Default: ", defaultDates.getPublishDate()); const { handleSubmit, formState, control, setValue, getValues, clearErrors, reset } = useForm({ mode: "all", resolver: yupResolver(schema), reValidateMode: "onChange", defaultValues: { title: "", - publishDate: defaultDates.getPublishDate(), + publishDate: overrideDefaultValues?.publishDate ?? defaultDates.getPublishDate(), publishEndDate: overrideDefaultValues?.publishEndDate ?? defaultDates.getPublishEndDate(), jobDuration: [INITIAL_JOB_DURATION, INITIAL_JOB_DURATION + 1], jobStartDate: null, @@ -72,7 +73,7 @@ export default (schema, overrideDefaultValues) => { clearErrors(); } }, - [clearErrors, isLoggedIn]); + [clearErrors, isLoggedIn]); return { success,