-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1030 from OneCommunityGlobal/yufei_make_intangibl…
…e_time_number_having_mouseover_explanation Yufei - make intangible time numbers having a mouseover explanation editable by the owner
- Loading branch information
Showing
12 changed files
with
239 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,48 @@ | ||
import axios from 'axios'; | ||
import { ENDPOINTS } from '../utils/URL'; | ||
|
||
import * as types from './../constants/mouseoverTextConstants'; | ||
|
||
export const getMouseoverTextAction = payload => { | ||
return { | ||
type: types.GET_MOUSEOVER_TEXT, | ||
payload, | ||
}; | ||
} | ||
|
||
export const getMouseoverText = () => async dispatch => { | ||
try { | ||
const { data } = await axios.get(ENDPOINTS.MOUSEOVERTEXT()); | ||
// console.log('Fetched mouseoverText data:', data); // Verify the fetched data | ||
return dispatch(getMouseoverTextAction(data)); | ||
} catch (error) { | ||
console.log('Error fetching mouseoverText:', error); | ||
} | ||
}; | ||
|
||
export const createMouseoverTextAction = payload => { | ||
return { | ||
type: types.CREATE_MOUSEOVER_TEXT, | ||
payload, | ||
}; | ||
} | ||
|
||
export const createMouseoverText = mouseoverText => async dispatch => { | ||
await axios.post(ENDPOINTS.MOUSEOVERTEXT(), mouseoverText) | ||
return dispatch(createMouseoverTextAction(mouseoverText)) | ||
} | ||
|
||
export const updateMouseoverTextAction = payload => { | ||
return { | ||
type: types.UPDATE_MOUSEOVER_TEXT, | ||
payload, | ||
}; | ||
} | ||
|
||
export const updateMouseoverText = (mouseoverTextId, mouseoverText) => { | ||
return async dispatch => { | ||
await axios.put(ENDPOINTS.MOUSEOVERTEXT_BY_ID(mouseoverTextId), mouseoverText) | ||
.then(dispatch(updateMouseoverTextAction(mouseoverText))); | ||
} | ||
} | ||
|
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
98 changes: 98 additions & 0 deletions
98
src/components/mouseoverText/MouseoverTextTotalTimeEditButton.jsx
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,98 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { ENDPOINTS } from '../../utils/URL'; | ||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Label, Input } from 'reactstrap'; | ||
import { toast } from 'react-toastify'; | ||
import { connect } from 'react-redux'; | ||
import { createMouseoverText, updateMouseoverText } from '../../actions/mouseoverTextAction'; | ||
|
||
|
||
function MouseoverTextTotalTimeEditButton({ | ||
createMouseoverText, | ||
updateMouseoverText, | ||
onUpdate, | ||
mouseoverTextId, | ||
}) { | ||
const [modalOpen, setModalOpen] = useState(false); | ||
const [newText, setNewText] = useState(''); | ||
|
||
|
||
const handleUpdateText = () => { | ||
setModalOpen(true); | ||
}; | ||
|
||
const handleSaveText = () => { | ||
const mouseoverTextFormat = { | ||
newMouseoverText: newText, | ||
}; | ||
if (newText) { | ||
updateMouseoverText(mouseoverTextId, mouseoverTextFormat); | ||
toast.success('Mouseover Text updated!'); | ||
} else { | ||
createMouseoverText(mouseoverTextFormat); | ||
toast.success('Mouseover Text created!'); | ||
} | ||
setModalOpen(false); | ||
onUpdate(newText); | ||
}; | ||
|
||
const handleCancelSave = () => { | ||
setModalOpen(false); | ||
}; | ||
|
||
|
||
return ( | ||
<div> | ||
<div> | ||
<i | ||
className="fa fa-pencil-square-o" | ||
aria-hidden="true" | ||
style={{ marginLeft: '5px', cursor: 'pointer' }} | ||
onClick={handleUpdateText} | ||
></i> | ||
<Modal isOpen={modalOpen} toggle={() => setModalOpen(!modalOpen)}> | ||
<ModalHeader toggle={() => setModalOpen(!modalOpen)}>Edit Mouseover Text</ModalHeader> | ||
<ModalBody> | ||
<Label for="newText">New Text</Label> | ||
<Input | ||
type="text" | ||
name="newText" | ||
id="newText" | ||
value={newText} | ||
onChange={(e) => setNewText(e.target.value)} | ||
/> | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button color="primary" onClick={handleSaveText}> | ||
Save | ||
</Button>{' '} | ||
<Button color="secondary" onClick={handleCancelSave}> | ||
Cancel | ||
</Button> | ||
</ModalFooter> | ||
</Modal> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
|
||
|
||
|
||
const mapStateToProps = (state) => { | ||
return { | ||
mouseoverText: state?.mouseoverText?.[0]?.mouseoverText, | ||
mouseoverTextId: state?.mouseoverText?.[0]?._id, | ||
}; | ||
}; | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
createMouseoverText: mouseoverText => dispatch(createMouseoverText(mouseoverText)), | ||
updateMouseoverText: (mouseoverTextId, mouseoverText) => | ||
dispatch(updateMouseoverText(mouseoverTextId, mouseoverText)), | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(MouseoverTextTotalTimeEditButton); | ||
|
||
|
||
|
||
|
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,3 @@ | ||
export const CREATE_MOUSEOVER_TEXT = 'CREATE_MOUSEOVER_TEXT'; | ||
export const GET_MOUSEOVER_TEXT = 'GET_MOUSEOVER_TEXT'; | ||
export const UPDATE_MOUSEOVER_TEXT = 'UPDATE_MOUSEOVER_TEXT'; |
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,20 @@ | ||
import * as types from './../constants/mouseoverTextConstants'; | ||
|
||
const initialState = null; | ||
|
||
export const mouseoverTextReducer = (state= initialState, action) => { | ||
switch(action.type) { | ||
case types.GET_MOUSEOVER_TEXT: | ||
const data = action.payload; | ||
return data; | ||
|
||
case types.CREATE_MOUSEOVER_TEXT: | ||
return state; | ||
|
||
case types.UPDATE_MOUSEOVER_TEXT: | ||
return state; | ||
|
||
default: | ||
return state; | ||
} | ||
} |
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