From 5c33fc8116d34988fbdeeff8e8786b9364a6cd60 Mon Sep 17 00:00:00 2001 From: aayush3416 <87783633+aayush3416@users.noreply.github.com> Date: Sat, 10 Jun 2023 20:05:35 -0400 Subject: [PATCH 1/4] only update date when there are changes --- src/frontend/pages/sponsors/hooks/sponsor-form.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/frontend/pages/sponsors/hooks/sponsor-form.js b/src/frontend/pages/sponsors/hooks/sponsor-form.js index 680320a..c5bf477 100644 --- a/src/frontend/pages/sponsors/hooks/sponsor-form.js +++ b/src/frontend/pages/sponsors/hooks/sponsor-form.js @@ -65,6 +65,7 @@ const reducer = (state, action) => { form: { ...state.form, name: action.payload, + lastUpdated: state.form.name === action.payload ? state.form.lastUpdated : new Date().toISOString(), }, }; case 'UPDATE_SPONSOR_WEBSITE': @@ -74,6 +75,7 @@ const reducer = (state, action) => { form: { ...state.form, website: action.payload, + lastUpdated: state.form.website === action.payload ? state.form.lastUpdated : new Date().toISOString(), }, }; case 'UPDATE_SPONSOR_TIER_ID': @@ -289,7 +291,8 @@ const useSponsorForm = (sponsorId, input = {}) => { } else { await api.sponsors.addSponsor(data); } - + const updatedLastUpdated = new Date().toISOString(); + dispatch({ type: 'UPDATE_LAST_UPDATED', payload: updatedLastUpdated }); // onSuccess: closeForm(); } catch (e) { From 80449030e070f1cb0221cc0fef245d097f3bb86b Mon Sep 17 00:00:00 2001 From: aayush3416 <87783633+aayush3416@users.noreply.github.com> Date: Thu, 15 Jun 2023 22:59:56 -0400 Subject: [PATCH 2/4] fix drop-down menu error on Sponsor Level --- src/frontend/pages/sponsors/hooks/sponsor-form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/pages/sponsors/hooks/sponsor-form.js b/src/frontend/pages/sponsors/hooks/sponsor-form.js index c5bf477..391e7d3 100644 --- a/src/frontend/pages/sponsors/hooks/sponsor-form.js +++ b/src/frontend/pages/sponsors/hooks/sponsor-form.js @@ -22,7 +22,7 @@ const initialState = (inputState) => ({ sponsorId: 0, name: '', website: '', - tierId: '', // !NOTE: initial value is string to allow selector to display placeholder value. + tierId: '1', // !NOTE: initial value is string to allow selector to display placeholder value. termYear: '', termSeason: '', description: '', From fe5656b3094cee32bb9e59970b7019071ff4dc56 Mon Sep 17 00:00:00 2001 From: aayush3416 <87783633+aayush3416@users.noreply.github.com> Date: Tue, 20 Jun 2023 11:47:20 -0400 Subject: [PATCH 3/4] undo changes and make it the same as main branch --- src/frontend/pages/sponsors/hooks/sponsor-form.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/frontend/pages/sponsors/hooks/sponsor-form.js b/src/frontend/pages/sponsors/hooks/sponsor-form.js index 391e7d3..c581cdf 100644 --- a/src/frontend/pages/sponsors/hooks/sponsor-form.js +++ b/src/frontend/pages/sponsors/hooks/sponsor-form.js @@ -65,7 +65,7 @@ const reducer = (state, action) => { form: { ...state.form, name: action.payload, - lastUpdated: state.form.name === action.payload ? state.form.lastUpdated : new Date().toISOString(), + // lastUpdated: state.form.name === action.payload ? state.form.lastUpdated : new Date().toISOString(), }, }; case 'UPDATE_SPONSOR_WEBSITE': @@ -75,7 +75,7 @@ const reducer = (state, action) => { form: { ...state.form, website: action.payload, - lastUpdated: state.form.website === action.payload ? state.form.lastUpdated : new Date().toISOString(), + // lastUpdated: state.form.website === action.payload ? state.form.lastUpdated : new Date().toISOString(), }, }; case 'UPDATE_SPONSOR_TIER_ID': @@ -296,7 +296,9 @@ const useSponsorForm = (sponsorId, input = {}) => { // onSuccess: closeForm(); } catch (e) { - updateFailure(`Could not ${state.exists ? "update" : "add"} sponsor: ${e.message}`); + updateFailure( + `Could not ${state.exists ? 'update' : 'add'} sponsor: ${e.message}`, + ); // eslint-disable-next-line no-console console.error(e); } From 6732e3edd26ee5b6277857fce3400d0212c24538 Mon Sep 17 00:00:00 2001 From: aayush3416 <87783633+aayush3416@users.noreply.github.com> Date: Fri, 23 Jun 2023 14:22:49 -0400 Subject: [PATCH 4/4] try fixing last updated bug --- .../pages/sponsors/hooks/sponsor-form.js | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/frontend/pages/sponsors/hooks/sponsor-form.js b/src/frontend/pages/sponsors/hooks/sponsor-form.js index c581cdf..189e1c0 100644 --- a/src/frontend/pages/sponsors/hooks/sponsor-form.js +++ b/src/frontend/pages/sponsors/hooks/sponsor-form.js @@ -1,11 +1,11 @@ -import { useReducer, useCallback, useEffect, useMemo } from 'react'; +import { useReducer, useCallback, useEffect, useMemo, useState } from 'react'; import api from '../../../api'; import { useHistory } from 'react-router-dom'; import FormData from 'form-data'; import useSponsors from '../../../hooks/sponsors'; import { toServerSponsor } from '../../../utils/sponsors/sponsor-utils'; - +import moment from 'moment'; const TODAY = new Date(); // Used for setting sponsor join date boundaries: @@ -65,7 +65,6 @@ const reducer = (state, action) => { form: { ...state.form, name: action.payload, - // lastUpdated: state.form.name === action.payload ? state.form.lastUpdated : new Date().toISOString(), }, }; case 'UPDATE_SPONSOR_WEBSITE': @@ -75,7 +74,6 @@ const reducer = (state, action) => { form: { ...state.form, website: action.payload, - // lastUpdated: state.form.website === action.payload ? state.form.lastUpdated : new Date().toISOString(), }, }; case 'UPDATE_SPONSOR_TIER_ID': @@ -150,7 +148,29 @@ const useSponsorForm = (sponsorId, input = {}) => { const [state, dispatch] = useReducer(reducer, initialState(input)); const history = useHistory(); const { sponsorTiers, sponsors } = useSponsors(); + const [isFormDirty, setFormDirty] = useState(false); // Track form modifications + + const [saveLastUpdated, setSaveLastUpdated] = useState( + state.form.lastUpdated + ? moment(state.form.lastUpdated).format('LLL') + : null, + ); + + useEffect(() => { + if (!isFormDirty && state.form.lastUpdated) { + setSaveLastUpdated(moment(state.form.lastUpdated).format('LLL')); + } + }, [state.form.lastUpdated, isFormDirty]); + const handleSave = useCallback(() => { + const currentDate = new Date().toLocaleString(); + console.log('Save date and time:', currentDate); // Log the updated date and time + setSaveLastUpdated(moment(currentDate).format('LLL')); + setFormDirty(false); + }, []); + useEffect(() => { + console.log('Last Updated', saveLastUpdated); // Log the updated date and time + }, [saveLastUpdated]); /** * Load Sponsor Data by ID: */ @@ -245,7 +265,6 @@ const useSponsorForm = (sponsorId, input = {}) => { }, [dispatch], ); - /** * Save and close Functions */ @@ -291,9 +310,8 @@ const useSponsorForm = (sponsorId, input = {}) => { } else { await api.sponsors.addSponsor(data); } - const updatedLastUpdated = new Date().toISOString(); - dispatch({ type: 'UPDATE_LAST_UPDATED', payload: updatedLastUpdated }); // onSuccess: + handleSave(); closeForm(); } catch (e) { updateFailure( @@ -315,7 +333,6 @@ const useSponsorForm = (sponsorId, input = {}) => { } }, [sponsorId, closeForm]); // END Save and close functions - /** UTILITY FUNCTIONS: */ /** * Calculate Years for Selector. @@ -356,6 +373,9 @@ const useSponsorForm = (sponsorId, input = {}) => { saveForm, closeForm, deleteForm, + isFormDirty, + saveLastUpdated, + handleSave, }; };