Skip to content

voxvanhieu/nd0191-c2-Project-Employee-Polls

 
 

Repository files navigation

Employee Polls Project

In the final exercise of Udacity’s React Nanodegree, students build an interactive voting portal. Users can log in, post new polls, and vote on existing ones. The intuitive interface allows easy navigation between polls.

Run the project

To run the project, you can follow these steps:

  1. Clone or download the project to local repoitory
  2. Make sure you node.js environment has been installed
  3. Open terminal at the root of repository
  4. Run command: npm install in order to install all the project's dependencies
  5. Run command: npm start to start project. Press F5 in VSCode to start the debug session
  6. Run command: npm test to start the Unit Test process

Setup project

Clone the starter code project

Clone this Starter code. Basically, this code is initialized by the Create React App to bootstrap the project

Command

npx create-react-app employee-polls
cd employee-polls
npm i @reduxjs/toolkit react-router-dom react-hook-form react-redux react-redux-loading-bar yup @hookform/resolvers

Install NextUI

npm i @nextui-org/react framer-motion
npm i -D tailwindcss
npx tailwindcss init

ESLint

npm i -g eslint

Jest

npm i --save-dev jest

Other package

npm i @react-stately/data

Data

The _DATA.js file represents a fake database and methods that let you access the data.

There are two types of objects stored in our database:

  • Users
  • Questions

Users

Users include:

Attribute Type Description
id String The user’s unique identifier
password String The user’s password in order to log in the application
name String The user’s first name and last name
avatarURL String The path to the image file
questions Array A list of ids of the polling questions this user created
answers Object The object's keys are the ids of each question this user answered. The value of each key is the answer the user selected. It can be either 'optionOne' or 'optionTwo' since each question has two options.

Questions

Questions include:

Attribute Type Description
id String The question’s unique identifier
author String The author’s unique identifier
timestamp String The time when the question was created
optionOne Object The first voting option
optionTwo Object The second voting option

Voting Options

Voting options are attached to questions. They include:

Attribute Type Description
votes Array A list that contains the id of each user who voted for that option
text String The text of the option

Your code will talk to the database via 4 methods:

  • _getUsers()
  • _getQuestions()
  • _saveQuestion(question)
  • _saveQuestionAnswer(object)
  1. _getUsers() Method

Description: Get all of the existing users from the database.
Return Value: Object where the key is the user’s id and the value is the user object.

  1. _getQuestions() Method

Description: Get all of the existing questions from the database.
Return Value: Object where the key is the question’s id and the value is the question object.

  1. _saveQuestion(question) Method

Description: Save the polling question in the database. If one of the parameters are missing, an error is thrown. Parameters: Object that includes the following properties: author, optionOneText, and optionTwoText. More details about these properties:

Attribute Type Description
author String The id of the user who posted the question
optionOneText String The text of the first option
optionTwoText String The text of the second option

Return Value: An object that has the following properties: id, author, optionOne, optionTwo, timestamp. More details about these properties:

Attribute Type Description
id String The id of the question that was posted
author String The id of the user who posted the question
optionOne Object The object has a text property and a votes property, which stores an array of the ids of the users who voted for that option
optionTwo Object The object has a text property and a votes property, which stores an array of the ids of the users who voted for that option
timestamp String The time when the question was created
  1. _saveQuestionAnswer(object) Method

Description: Save the answer to a particular polling question in the database. If one of the parameters are missing, an error is thrown. Parameters: Object that contains the following properties: authedUser, qid, and answer. More details about these properties:

Attribute Type Description
authedUser String The id of the user who answered the question
qid String The id of the question that was answered
answer String The option the user selected. The value should be either "optionOne" or "optionTwo"

Screenshots

Login Page

Login

Alert

image

Home

image

Add

image

Add result

image

Tooltip

image

Detail voted

image

detail unvoted

image

After voted

image

Leaderboard

image

Logout

image

404

image

Test result

image

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 97.5%
  • HTML 2.4%
  • CSS 0.1%