For this test, you are given the task of developing a feature for one of our products.
Below is an example of the appointment form, it does not have to look like this:
- Allow the user to select a service.
- The user must select one service before the rest of the form is shown.
- Depending on the service selected, show a custom form to the user so they can enter their details.
- When the user submits the form, log the field values to the console (this should also include the selected service value).
- After the form has been submitted, reset the form so that the user can make a new appointment request.
Here is the tricky part. Depending on the service selected, different input and labels will need to be shown in the form.
Services: data/services.json
Form: data/form.json
Services
: contains all the services a user can select.
Form
: describes the form constructions that are possible. When a user selects a service
, you will need to look for the right form description containing the service
in it's property services
and show the right title and inputs (with the right type and label) for the user to fill out.
The form containing *
in its services is used if no other form description contains the service the user selected.
-
Instead of using the local
json
files, fetch the data using Next.js api routes. -
Implement CRUD endpoints for the Services. JSON files can be used to seed data in memory at server startup, and user should be able to dynamically add and remove services.
-
Add field validation to prevent the user from submitting invalid information:
- Email: must be a valid email
- Phone: must only contain numbers
- Text: must not be an empty string
""
We have setup a basic Next.js app for you to build on. To get started, run the following commands from your terminal:
npm install
npm run dev
The app will run on http://localhost:3000 and any changes in your code will be reflected there without restarting your server.
Styles: in styles.scss Entry point: pages/index.js Syntax: ES6
true + false > 2 + true
true
false
TypeError
NaN
"1" - -"1"
0
2
11
"11"
new array(5).toString()
",,,,"
[]
"[]"
var arr = ["foo", "bar"]
arr.length = 0;
arr.push("bin")
console.log(arr)
['foo', 'bar']
['foo', 'bar', 'bin']
['bin', 'foo', 'bar']
['bin']
10 > 9 > 8 === true
true
false
function bar() {
return foo;
foo = 10;
function foo() {}
var foo = ‘11’;
}
console.log(typeof bar());
number
function
undefined
string
Error