Skip to content

Commit

Permalink
replace value with defaultValue in the Field component so resource ca…
Browse files Browse the repository at this point in the history
…n be edited; update logic in handleSubmit in EditResource page b00tc4mp#484; update logoutUser logic so role is wiped sessionstorage when you log out b00tc4mp#430
  • Loading branch information
juditta99 committed Jun 18, 2024
1 parent 3b54c1e commit 66c0df4
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 11 deletions.
21 changes: 19 additions & 2 deletions staff/judy-grayland/project/app/src/components/Field.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,29 @@ function Field(props) {
return (
<>
<label htmlFor={props.inputId}>{props.children}</label>

<input
name={props.name}
type={props.type ?? 'text'}
id={props.inputId}
value={props.value}
/>
defaultValue={props.value}
></input>
{/* <label htmlFor={props.inputId}>{props.children}</label>
{props.defaultValue ? (
<input
name={props.name}
type={props.type ?? 'text'}
id={props.inputId}
defaultValue={props.defaultValue}
/>
) : (
<input
name={props.name}
type={props.type ?? 'text'}
id={props.inputId}
value={props.value}
/>
)} */}
</>
)
}
Expand Down
4 changes: 4 additions & 0 deletions staff/judy-grayland/project/app/src/logic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import logoutUser from './logoutUser'
import createResource from './createResource'
import retrieveResources from './retrieveResources'
import deleteResource from './deleteResource'
import editResource from './editResource'
import context from './context'

const logic = {
registerUser,
Expand All @@ -12,6 +14,8 @@ const logic = {
createResource,
retrieveResources,
deleteResource,
editResource,
context,
}

export default logic
1 change: 1 addition & 0 deletions staff/judy-grayland/project/app/src/logic/logoutUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import context from './context'
function logoutUser() {
context.sessionUserId = null
context.token = null
context.role = null
}

export default logoutUser
6 changes: 4 additions & 2 deletions staff/judy-grayland/project/app/src/pages/EditResource.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function EditResource() {
const formData = new FormData(event.currentTarget)
const data = {}

console.log(formData.entries())
for (let [key, val] of formData.entries()) {
if (key === 'topic' && !data.topic) {
data.topic = [val]
Expand All @@ -65,10 +66,11 @@ function EditResource() {
data[key] = val
}
}
console.log(data)

try {
logic
.createResource(data)
.editResource(id, data)
.then(() => {
handleEditResourceSuccess()
})
Expand Down Expand Up @@ -129,7 +131,7 @@ function EditResource() {
<Field
name="description"
inputId="description-input"
value={resource.description}
defaultValue={resource.description}
>
Descripción
</Field>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DeleteResourceButton, EditResourceButton } from '../components'
import logic from '../logic'

import topicTranslations from '../logic/topicTranslations'

Expand All @@ -22,8 +23,12 @@ function ResourceActivity(props) {
<p>
Temas: <em>{translatedTopics.join(', ')}</em>
</p>
<EditResourceButton resourceId={props._id} />
<DeleteResourceButton resourceId={props._id} />
{logic.context.role === 'admin' && (
<>
<EditResourceButton resourceId={props._id} />
<DeleteResourceButton resourceId={props._id} />
</>
)}
</article>
)
}
Expand Down
9 changes: 7 additions & 2 deletions staff/judy-grayland/project/app/src/pages/ResourceBook.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DeleteResourceButton, EditResourceButton } from '../components'
import topicTranslations from '../logic/topicTranslations'
import logic from '../logic'

function ResourceBook(props) {
const translatedTopics = props.topic.map((topic) => topicTranslations[topic])
Expand All @@ -19,8 +20,12 @@ function ResourceBook(props) {
<p>
Temas: <em>{translatedTopics.join(', ')}</em>
</p>
<EditResourceButton resourceId={props._id} />
<DeleteResourceButton resourceId={props._id} />
{logic.context.role === 'admin' && (
<>
<EditResourceButton resourceId={props._id} />
<DeleteResourceButton resourceId={props._id} />
</>
)}
</article>
)
}
Expand Down
9 changes: 7 additions & 2 deletions staff/judy-grayland/project/app/src/pages/ResourceDate.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EditResourceButton, DeleteResourceButton } from '../components'
import topicTranslations from '../logic/topicTranslations'
import logic from '../logic'

function ResourceDate(props) {
const translatedTopics = props.topic.map((topic) => topicTranslations[topic])
Expand All @@ -19,8 +20,12 @@ function ResourceDate(props) {
<p>
Temas: <em>{translatedTopics.join(', ')}</em>
</p>
<EditResourceButton resourceId={props._id} />
<DeleteResourceButton resourceId={props._id} />
{logic.context.role === 'admin' && (
<>
<EditResourceButton resourceId={props._id} />
<DeleteResourceButton resourceId={props._id} />
</>
)}
</article>
)
}
Expand Down
4 changes: 3 additions & 1 deletion staff/judy-grayland/project/app/src/pages/ResourcesList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ function ResourcesList() {
)
})}

<Button onClick={handleNewResourceClick}>Crear nuevo recurso</Button>
{logic.context.role === 'admin' && (
<Button onClick={handleNewResourceClick}>Crear nuevo recurso</Button>
)}
</>
)
}
Expand Down

0 comments on commit 66c0df4

Please sign in to comment.