JSFiddle - React, Tailwind, and code Playground

by dimshik

JavaScript

var db = {
	persons: [
		{
			id: "1",
			name: "Dima",
			dishes: [
				{
					id: "1",
					price: "45.60",
					splitBy: 2
				},
				{
					id: "2",
					price: "30",
					splitBy: 1
				},
				{
					id: "5",
					price: "18",
					splitBy: 2
				}
			]
		},
		{
			id: "2",
			name: "Maya",
			dishes: []
		},
		{
			id: "3",
			name: "Arik",
			dishes: [
				{
					id: "1",
					price: "45.60",
					splitBy: 2
				}
			]
		},
		{
			id: "4",
			name: "Bob",
			dishes: []
		}
	],
	tempPersons: [
		{
			id: "-1",
			name: ""
		},
		{
			id: "-2",
			name: ""
		}
	],
	dishes: [
		{
			id: "1",
			price: "45.60",
			personsIds: ["1", "3"]
		},
		{
			id: "2",
			price: "30",
			personsIds: ["1"]
		},
		{
			id: "3",
			price: "12.50",
			personsIds: ["-1"] // a dish can be adde without a person, it will be added to a generated temp person
		},
		{
			id: "4",
			price: "6.90",
			personsIds: ["-2"] // a dish can be adde without a person, it will be added to a generated temp person
		},
		{
			id: "5",
			price: "18",
			personsIds: ["1"]
		},
	]
};