diff --git a/src/components/CustomerProfile.jsx b/src/components/CustomerProfile.jsx new file mode 100644 index 000000000..6507a059f --- /dev/null +++ b/src/components/CustomerProfile.jsx @@ -0,0 +1,9 @@ +import React from "react"; + +const CustomerProfile = ({id}) => { + return ( +

Customer {id} Profile

+ ) +} + +export default CustomerProfile; \ No newline at end of file diff --git a/src/components/SearchResults.jsx b/src/components/SearchResults.jsx index 8c70872e9..9d9383037 100644 --- a/src/components/SearchResults.jsx +++ b/src/components/SearchResults.jsx @@ -1,21 +1,25 @@ import React, { useState } from "react"; import moment from "moment"; +import CustomerProfile from "./CustomerProfile"; const Row = (props) => { const [highlight, setHighlight] = useState(false); const toggleHighlight = () => { setHighlight(!highlight); }; + const a = moment(props.result.checkOutDate); const b = moment(props.result.checkInDate); const days = a.diff(b, "days"); // 1 + + return ( toggleHighlight()} - style={{ - backgroundColor: highlight ? "yellow" : "", - }} - key={props.index} + onClick={() => toggleHighlight()} + style={{ + backgroundColor: highlight ? "yellow" : "", + }} + key={props.index} > {props.result.id} {props.result.title} @@ -26,34 +30,49 @@ const Row = (props) => { {props.result.checkInDate} {props.result.checkOutDate} {days} + + + ); }; -const SearchResultsOther = (props) => { +const SearchResults= (props) => { + + const [customerId, setCustomerId] = useState(); + + const getCustomerId = (result) => { + setCustomerId(result.id); + } + return ( - - - - - - - - - - - - - - - - {props.results.map((result) => { - return ( - - ) - })} - -
IdTitleFirst NameSurnameEmailRoom idCheck in dateCheck out dateNumber of nights
+
+ + + + + + + + + + + + + + + + + {props.results.map((result) => { + return ( + + ) + })} + +
IdTitleFirst NameSurnameEmailRoom idCheck in dateCheck out dateNumber of nightsShow profile
+ {customerId ? : null} + +
); }; -export default SearchResultsOther; +export default SearchResults; diff --git a/src/components/SearchResultsOther.jsx b/src/components/SearchResultsOther.jsx index d805d2b94..448b833ce 100644 --- a/src/components/SearchResultsOther.jsx +++ b/src/components/SearchResultsOther.jsx @@ -1,32 +1,11 @@ import React, {useState} from "react"; import moment from "moment"; -const SearchResults = (props) => { +const SearchResultsOthers = (props) => { const array = []; props.results.forEach(() => { array.push(false); - - }) - - /* - imagine we have five results - array = [false, false, false, false, false] - - highlight = array - - Each time a user clicks a row the clickHandler function is triggered below - - let's say user clicks on row 4 (index 3) - arrToObj = { ...highlight } this translates to {0:false, 1:false, 2:false, 3:false, 4:false} - arrToObj[3] = ( - (if false) true - else false - ) - setHighlight state will now return an object - - {0:false, 1:false, 2:false, 3:true, 4:false} - - */ + }) const [highlight, setHighlight] = useState(array); const toggleHighlight = (index) => { @@ -80,4 +59,4 @@ const SearchResults = (props) => { ); }; -export default SearchResults; \ No newline at end of file +export default SearchResultsOthers; \ No newline at end of file