Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. import React from 'react';
  2. import {
  3. Create,
  4. SimpleForm,
  5. TextInput,
  6. Toolbar,
  7. SaveButton,
  8. ReferenceInput,
  9. SelectInput,
  10. DateTimeInput,
  11. DateInput
  12. }
  13. from 'react-admin';
  14. import CancelButton from '../../layout/CancelButton.js'
  15.  
  16. const CustomToolbar = props => (
  17. <Toolbar {...props}>
  18. <SaveButton />
  19. <CancelButton />
  20. </Toolbar>
  21. );
  22.  
  23. const dateFormatter = v => {
  24. // v is a `Date` object
  25. console.log(v);
  26. if (!(v instanceof Date) || isNaN(v)) return;
  27. const pad = '00';
  28. const yy = v.getFullYear().toString();
  29. const mm = (v.getMonth() + 1).toString();
  30. const dd = v.getDate().toString();
  31. console.log(match);
  32. console.log(dd);
  33. return `${yy}-${(pad + mm).slice(-2)}-${(pad + dd).slice(-2)}`;
  34. };
  35.  
  36. const dateParser = v => {
  37. // v is a string of "YYYY-MM-DD" format
  38. console.log(v);
  39.  
  40. const match = /(\d{4})-(\d{2})-(\d{2})/.exec(v);
  41.  
  42. console.log(match);
  43.  
  44. if (match === null) return;
  45. const d = new Date(`${match[3]}/${parseInt(match[2], 10) - 1}/${match[1]}`);
  46. console.log(d);
  47. if (isNaN(d)) return;
  48. return d;
  49. };
  50.  
  51. export const CreateSurvey = props => (
  52. <Create {...props}>
  53. <SimpleForm redirect="list" toolbar={<CustomToolbar/>}>
  54. <ReferenceInput label="Organization" source="organization_id" reference="organization">
  55. <SelectInput optionText="organization_id" />
  56. </ReferenceInput>
  57. <TextInput source="name" />
  58. <TextInput source="description" />
  59. <TextInput source="instruction" />
  60. <DateInput source="begin_at" format={dateFormatter} parse={dateParser} />
  61. <DateInput source="finished_at" format={dateFormatter} parse={dateParser} />
  62. <TextInput source="latitude" />
  63. <TextInput source="longitude" />
  64. </SimpleForm>
  65. </Create>
  66. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement