-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* EIC Request * WIP * update url * remove util file * remove console statement
- Loading branch information
1 parent
fbc155b
commit 1dd2e76
Showing
7 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useEffect } from 'react'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import { selectDate as selectDateAction } from '../../../modules/date/actions'; | ||
import { | ||
setEICLegacy as setEICLegacyAction, | ||
} from '../../../modules/ui/actions'; | ||
|
||
function EIC() { | ||
const dispatch = useDispatch(); | ||
const selectDate = (date) => { dispatch(selectDateAction(date)); }; | ||
const setEICLegacy = (isLegacy) => { dispatch(setEICLegacyAction(isLegacy)); }; | ||
|
||
const eic = useSelector((state) => state.ui.eic); | ||
const eicLegacy = useSelector((state) => state.ui.eicLegacy); | ||
const scenario = useSelector((state) => state.ui.scenario); | ||
|
||
const requestBestDate = async () => { | ||
try { | ||
const url = `https://m80gyw03f7.execute-api.us-east-1.amazonaws.com/dev/scenarios?item_type=scenario&item_id=${scenario}`; | ||
const response = await fetch(url); | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok.'); | ||
} | ||
const data = await response.json(); | ||
const resolutionDate = data.resolution_date; | ||
|
||
if (resolutionDate === 'No valid date found') { | ||
console.error('No valid date found, using EIC Legacy mode'); | ||
setEICLegacy(true); | ||
return; | ||
} | ||
|
||
const dateObj = new Date(resolutionDate); | ||
selectDate(dateObj); | ||
} catch (error) { | ||
console.error('Error fetching the best date, using EIC Legacy mode:', error); | ||
setEICLegacy(true); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
if (scenario !== '' && eicLegacy === false && eic === 'si') { | ||
requestBestDate(); | ||
} | ||
}, []); | ||
|
||
return null; | ||
} | ||
|
||
export default EIC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters