Finally, we'll add the ability to assign users to tasks and see who is the assignee for a particular task.
Link to UserTag
component in Figma
- This component should receive an optional User object as a prop.
- If the user is null or undefined, then display the "Not assigned" message as shown in Figma.
- If there is no profile picture URL, then use the default icon provided in Figma.
- The profile picture should be a 32px by 32px circle.
-
Export the user icon from Figma as an SVG.
- Right-click on the icon, choose "Select layer > User icon", then click "Export User icon" in the Export panel of the right sidebar.
- Save the SVG in the
frontend/public
folder with a name likeuserDefault.svg
.
-
In
frontend/src/components
, create two new files:UserTag.tsx
andUserTag.module.css
. -
Write the
UserTag
component. It should be a "pure" component (no state or side effects). Make sure you cover all the possible cases with conditional rendering.- Use an
<img>
element to display the profile picture. To use the default icon we just downloaded, pass insrc="/userDefault.svg"
(or whatever file name you used).
❓ Hint: CORS errors
You might encounter a CORS (Cross-Origin Resource Sharing) permission error caused by the profile picture. This happens because browsers block requests for any resource that's not from the same origin (in our case,
localhost:3000
) by default for security reasons. You can ignore these errors and just use the example profile pictures that we provided (see Part 2.1). - Use an
-
Add styles to the
UserTag
component. You should just need some layout styling and aborder-radius
on the profile picture. -
Export
UserTag
fromcomponents/index.ts
. -
Optional: Add a
className
prop and pass it along to the outermost element in yourUserTag
JSX. You can use this prop to make layout easier in the next steps.
Link to updated TaskItem
component in Figma
TaskItem
should render aUserTag
to show who is assigned to the task.
- Add a
UserTag
within theTaskItem
component. Pass in the task's assignee as the user prop. - Add styling for the
UserTag
to give it a fixed width. If you added aclassName
prop toUserTag
, you can pass down styles to it just like with any built-in element. If not, it might be easiest to wrap theUserTag
in another<div>
.- You can pick a reasonable width, such as 12rem (192px).
- Be sure the
UserTag
sticks to the right side of theTaskItem
too. TheTaskItem
CSS we wrote earlier should make this happen already, but you might still have to fix something.
- Check the Home page to verify that
UserTag
s are displayed correctly.
Link to updated TaskForm
component in Figma
- The
TaskForm
should have another text field for the optional assignee ID. - In
"edit"
mode, theTaskForm
should callupdateTask
instead ofcreateTask
. It does not need to reset itself after submitting in this mode.
- In the
TaskForm
component, add aTextField
for the assignee and move the Save button next to it. You'll have to add a new row for these components in the JSX and another state variable liketitle
anddescription
. - Update the
handleSubmit
function to callcreateTask
ifmode
is"create"
andupdateTask
ifmode
is"edit"
. ForupdateTask
, make sure you include all Task fields, not just those visible in the form. Remember to callonSubmit
as well if the request succeeds.
Link to updated TaskDetail
page in Figma
- Show a
UserTag
for the task's assignee. - When "Edit task" is clicked, display the
TaskForm
component in edit mode with the data from this task. - When the
TaskForm
is submitted, display the task information view again with the updated task data.
-
In the
TaskDetail
page component, importUserTag
and use it to display the assignee. -
Add another state variable
isEditing
which will store a boolean indicating whether theTaskForm
is open. -
Set
isEditing
to true when the "Edit task" button is clicked. -
When
isEditing
is true, display aTaskForm
in edit mode prefilled with this task's data; otherwise, display the task information as we just implemented. Upon submission of theTaskForm
, changeisEditing
back to false and set thetask
state variable to the updated task in the callback. -
Test your changes by opening the
TaskDetail
page, clicking "Edit task," changing the values, and clicking Save. You can copy and paste user IDs from mongosh. Try this for multiple different tasks and try some special cases: empty form fields, a task ID instead of a user ID, a nonexistent ID, no change in the form, etc.🤔 For new developers: Thinking about the user experience
Pasting user IDs manually isn't a great user experience. In a real project, we could use some kind of dropdown selection menu, possibly with a search bar to filter by name. Can you think of other ways to design this interaction?
Remember to add, commit, and push your changes!
Previous | Up | Next |
---|---|---|
2.2. Implement the task detail page | Part 2 | 2.4. Make a pull request |