kiwicom / margarita

[not actively maintained] Mobile and Web application implementing Kiwi.com Tequila API
https://margarita.kiwi.com/
MIT License
208 stars 42 forks source link

Refactor DateInput margarita component #890

Closed KarinaDavtyan closed 5 years ago

KarinaDavtyan commented 5 years ago

The existing DateInput.js has this props

type Props = {|
  +onDateChange: (string, string) => void,
  +date: {
    +day: string,
    +month: string,
    +year: string,
  },
  +errors: {
    +day: string,
    +year: string,
  },
|};

which are controlled by the PassengerForm.js state and onDateChange is called every time one of the time periods changes

handleDayChange = (day: string) => {
    this.props.onDateChange(day, 'day');
  };

It was done this way so the BirthDate could be validated and composed in PassengerForm on button click.

But solving #836 noticed thatDateInput.ios.js wouldnt require any validation and therefore the onDateChange would be outputting correct Date right away, so it would be working differently depending on the platform.

What would be the best approach to solve it?

1) Try to refactor DateInput.js by pre filling day, month and year so it would be returning date on button click

2) Keep components different and pass different props depending on the platform

KarinaDavtyan commented 5 years ago

What do you think? @FilipMessa @jvaclavik @aalises @JoseDuSV