Instructions for Next.js Developer Technical Assessment

GoalComplete a Next.js tool to help parse and visualize a graph data structure as an adjacency matrix.

ScoreOut of 80 - for code quality, functionality, completedness, fidelity, animations and overall design.

Maximum Time3 hours

ClimateCompare dashboard without data ClimateCompare dashboard with data

Project Details

Description

Core Features

Your Role

Overall App Flow

  1. Start The user types their name, which is saved in a cookie, and is redirected to the dashboard/ route. The presence of a cookie is checked in the dashboard to ensure the user is authenticated.
  2. Input The user enters graph data into the editor (e.g., A->B), adhering to the instructions.
  3. Server Processing The server processes the input, validating it and extracting nodes and edges.
  4. State Update The Dashboard component updates its state with the nodes and edges returned by the server.
  5. Graph Display The Matrix component renders the adjacency matrix based on the user input.
  6. Reset/Error Handling The user can reset the input or see detailed error messages if the input is invalid.

Tech Stack

Task 1 - Setting up your development environment

  1. Fork this GitHub respository onto your personal GitHub account and clone it to your machine - this folder contains the skeleton for the project you will be working on. The time allocation (max. 3 hours) will start from the point you fork this repository.
  2. Navigate to this repo's folder from your machine. Inside this folder you see a single folder named src/. This is where you will spend your time writing designing and code. You can ignore the folder named /instructions.
    • Ensure that you only edit / append code to the respective files within these folders which have been specified in the instructions. Do not change any other files, as this may result in our test scripts failing to score your submission.
    • Your final submission will be made as a pull request to this Github repository. You will receive your score as a comment to this pull request on GitHub itself.
    • Feel free to commit and push regularly to your personal fork of our repository. However, only submit a pull request to our GitHub repository after you complete the entire assessment.
  3. Open the repo's folder using your favorite text editor / IDE.
  4. Run npm i via the terminal in the src/ folder to install the necessary packages.
  5. The tasks below will specify if any additional files need to be added to this directory or its subdirectories. Don't add any additional files otherwise.
  6. Task 1 is now complete. You may now move on to Task 2.

Task 2 - Completing the root route

20 marks
  1. Open the src/app/page.tsx file. Use the following GIF for your reference for this task:
  2. Graph Renderer Login Page
  3. Recreate the above UI as the root app route - as closely as possible - using responsive design principles, by following these steps:
    1. Set up the main layout by using a <section> element for layout and apply Tailwind CSS classes to center content both vertically and horizontally.
    2. Greet the user with a <div> containing a welcome message. Add Tailwind classes to add a pulsing animation and gradient effect from teal colors to make the text dynamic.
    3. Create a form container by adding a <div> with a 2px border, 5px padding and background color bg-slate-50 to create a rounded container. Include a <label> with "What's your name?".
    4. Add an input field to the container using the existing Input component with a suitable id, type, and placeholder text.
    5. Include a submit button with the label "Continue" using the provided Button component with type = "submit" and theme = "primary".
    6. Handle form submission by adding an action inside the form that calls the imported asynchronous function (e.g., redirectToDashboard). If the action fails, set an error using the state variable error.
    7. Use Tailwind CSS classes like border-gray-300, rounded, text-gray-600 for final touches, ensuring consistent design and spacing.

    Write code for this task within the TASK 2.2 comment fence in page.tsx

  4. Open the src/app/actions.ts file.
  5. Complete the redirectToDashboard function based on the following steps:
    1. Get the user's name from formData and cast it as a string.
    2. Ensure the name is not empty; return the error message "Hey, your name is missing!" if it is.
    3. Clean the name by trimming, lowercasing, and removing extra whitespace.
    4. Use the cookies API to set a cookie with the name gr-name and the cleaned value.
    5. If the above was successful, call the redirect function to navigate the user to /dashboard.

    Write code for this task within the TASK 2.4 comment fence in actions.ts

  6. Task 2 is now complete. Feel free to test your code using npm run dev on the src/ folder. Commit and push your work to your personal forked repository. You may now move on to Task 3.

Task 3 - Completing the dashboard route

40 marks
  1. Open the src/app/dashboard/page.tsx file.
  2. Implement the dashboard route as a server component using the following steps:
    1. Use the cookies function to retrieve the gr-name cookie from the user's browser.
    2. If the gr-name cookie does not exist or has no value, use the redirect function to send the user back to the homepage (/).
    3. If the gr-name cookie exists, render the Header component wrapped inside a Suspense tag with a fallback of HeaderSkeleton.
    4. Use the Dashboard component to render the dashboard interface.

    Write code for this task within the TASK 3.2 comment fence in page.tsx

  3. Open the src/app/dashboard/actions.tsx file.
  4. Complete the renderGraph server action, which is called when a user submits graph notation data via the "Generate" button in the dashboard.tsx component.
    This form actions recieves formData as input, from which the graph-notation key has been extracted as a string.
    This string represents the graph in a specific notation format and processes the input to produce nodes and edges that will be used to render the graph back in the dashboard.tsx.

    Follow these steps to complete the renderGraph function:
    1. Input Format: The input will be a multiline string where each line represents an edge in the graph using the following format:
      • Each line should follow the pattern: source->target.
      • Each source and target must be a single character, and no spaces are allowed in a line.
      • Each line represents a directed, unweighted edge from the source node to the target node.
      Example input:
      A->B
      B->C
      C->D
    2. Error Handling:
      • If any line does not follow the expected source->target pattern, you should throw an error and return a helpful error message.
        • For example, if the input is malformed, return an error message like: Hey, there was an error parsing line 3 of your graph notation!.
      • If the parsing process fails for any reason, return an error message like: Hey, there was an error parsing your graph notation!.
    3. Max Nodes Constraint:
      • You should only allow up to 6 nodes, set by the MAX_NODES constant. If the input contains more than 6 unique nodes, slice the list to only include the first 6.
    4. Node and Edge Processing:
      • For each valid line, extract the source and target nodes.
      • Store each node in a Set to ensure uniqueness (since a node may appear in multiple edges).
      • Also store each edge in a Set, ensuring that duplicate edges are not included.
    5. Output Format: Once the input is parsed, return an object with two properties:
      • edges: An array of unique edges, each represented as a concatenation of the source and target (e.g., "AB").
      • nodes: An array of unique node names, up to a maximum of 6.

    Examples

    Here are a few examples of valid inputs to the server action (after parsing formData) and their expected outputs:

    • Example #1:
    • Input
      A->B
      B->C
      C->D

      Output

      {
        edges: ["AB", "BC", "CD"],
        nodes: ["A", "B", "C", "D"]
      }
    • Example #2:
    • Input
      A->B
      B->C
      C->B
      D->E
      C->B
      F->G

      Output

      {
        edges: ["AB","BC", "CB", "DE", "FG"], // Duplicate edges are removed
        nodes: ["A", "B", "C", "D", "E", "F"]  // Only the first 6 nodes
      }
    • Example #3:
    • Input
      A->B
      C-D

      Output

      {
        message: "Hey, there was an error parsing line 2 of your graph notation!"
      }

    Write code for this task within the TASK 3.4 comment fence in actions.ts

  5. Task 3 is now complete. Feel free to test your code using npm run dev on the src/ folder. Commit and push your work to your personal forked repository. You may now move on to Task 4.

Task 4 - Completing the dashboard component

20 marks
  1. Open the src/components/dashboard.tsx file. Use the following GIF for your reference for this task:
  2. Graph Renderer Dashboard Page
  3. Recreate the above component as a client component - as closely as possible - using responsive design principles, by following these steps. Note that some of the tasks have been completed for you:
    1. The dashboard should have a main section with a background color of bg-teal-100 and should be a flex container. Inside, create two primary sections: one for the instructions and one for the "Graph Editor" and "Adjacency Matrix".
      This has been completed for you.
    2. Create a header with a background color of bg-teal-500 and text color of text-white. Use bold and uppercase text with tracking for better readability.
      This has been completed for you.
    3. Under the header, include a bulleted list explaining how to use the graph editor. Use the text-teal-700 and font-bold classes to highlight important text.
      This has been completed for you.
    4. Below the instructions, create the "Graph Editor" interface. This should have a label instructing the user to enter their graph notation.
    5. Add a TextArea component for the graph notation input (e.g., A->B). It should have an id = "graph-notation" and a placeholder = "e.g. A->B".
    6. Add a form that handles submissions and resets. The form should call the renderGraph function with the formData.
    7. If there is an error during form submission, display it using the Error component, and reset the nodes and edges state.
    8. If successful, display the graph nodes and edges using the form's response.
    9. Add a "Generate" button using the Button component with the primary theme for submitting the form.
    10. Add a "Clear" button using the Button component with the secondary theme to reset the form.
    11. Next to the "Graph Editor", create the "Adjacency Matrix" section with the same header styling.
    12. Use the Matrix component to display the adjacency matrix. Pass in the graphNodes and graphEdges as props to the Matrix component.
    13. Use the useState hook to manage the error, graphNodes, and graphEdges states.
      The states have been initialized for you.
    14. If an error occurs, display the error message using the Error component.
    15. If the form is reset, clear the error, graph nodes, and graph edges states.
    16. Make sure to use the provided custom components: Button, Error, Matrix, and TextArea.

    Write code for this task within the TASK 4.2 comment fence in dashboard.tsx

  4. Congratulations on completing this assessment! You may now submit a pull request (ensuring that all local changes have been pushed) to the main repository from your forked repository to confirm your submission.

    Make sure to include your name in the pull request message, along with any additional details in a README.md if you wish to explain / comment on any of the solutions for the previous tasks.