├── .gitignore ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt └── src ├── App.js ├── components ├── Cita.js └── Formulario.js ├── index.css ├── index.js └── serviceWorker.js /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "citas", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "react": "^16.12.0", 7 | "react-dom": "^16.12.0", 8 | "react-scripts": "3.2.0", 9 | "uuid": "^3.3.3" 10 | }, 11 | "scripts": { 12 | "start": "react-scripts start", 13 | "build": "react-scripts build", 14 | "test": "react-scripts test", 15 | "eject": "react-scripts eject" 16 | }, 17 | "eslintConfig": { 18 | "extends": "react-app" 19 | }, 20 | "browserslist": { 21 | "production": [ 22 | ">0.2%", 23 | "not dead", 24 | "not op_mini all" 25 | ], 26 | "development": [ 27 | "last 1 chrome version", 28 | "last 1 firefox version", 29 | "last 1 safari version" 30 | ] 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codigoconjuan/citas_react/4ea2b65287c2f2c6e7948be320d64dfadf502373/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | Administración de Pacientes 28 | 29 | 30 | 31 | 32 | 33 | 34 |
35 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codigoconjuan/citas_react/4ea2b65287c2f2c6e7948be320d64dfadf502373/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codigoconjuan/citas_react/4ea2b65287c2f2c6e7948be320d64dfadf502373/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Fragment, useState, useEffect } from 'react'; 2 | import Formulario from './components/Formulario'; 3 | import Cita from './components/Cita'; 4 | 5 | function App() { 6 | 7 | // Citas en local storage 8 | let citasIniciales = JSON.parse(localStorage.getItem('citas')); 9 | if(!citasIniciales) { 10 | citasIniciales = []; 11 | } 12 | 13 | // Arreglo de citas 14 | const [citas, guardarCitas] = useState(citasIniciales); 15 | 16 | // Use Effect para realizar ciertas operaciones cuando el state cambia 17 | useEffect( () => { 18 | let citasIniciales = JSON.parse(localStorage.getItem('citas')); 19 | 20 | if(citasIniciales) { 21 | localStorage.setItem('citas', JSON.stringify(citas)) 22 | } else { 23 | localStorage.setItem('citas', JSON.stringify([])); 24 | } 25 | }, [citas] ); 26 | 27 | // Función que tome las citas actuales y agregue la nueva 28 | const crearCita = cita => { 29 | guardarCitas([ ...citas, cita ]); 30 | } 31 | 32 | // Función que elimina una cita por su id 33 | const eliminarCita = id => { 34 | const nuevasCitas = citas.filter(cita => cita.id !== id ); 35 | guardarCitas(nuevasCitas); 36 | } 37 | 38 | // Mensaje condicional 39 | const titulo = citas.length === 0 ? 'No hay citas' : 'Administra tus Citas'; 40 | 41 | return ( 42 | 43 |

Administrador de Pacientes

44 | 45 |
46 |
47 |
48 | 51 |
52 |
53 |

{titulo}

54 | {citas.map(cita => ( 55 | 60 | ))} 61 |
62 |
63 |
64 |
65 | ); 66 | } 67 | 68 | export default App; 69 | -------------------------------------------------------------------------------- /src/components/Cita.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | 5 | const Cita = ({cita, eliminarCita}) => ( 6 |
7 |

Mascota: {cita.mascota}

8 |

Dueño: {cita.propietario}

9 |

Fecha: {cita.fecha}

10 |

Hora: {cita.hora}

11 |

Sintomas: {cita.sintomas}

12 | 13 | 17 |
18 | ); 19 | 20 | Cita.propTypes = { 21 | cita: PropTypes.object.isRequired, 22 | eliminarCita: PropTypes.func.isRequired 23 | } 24 | 25 | export default Cita; -------------------------------------------------------------------------------- /src/components/Formulario.js: -------------------------------------------------------------------------------- 1 | import React, { Fragment, useState } from 'react'; 2 | import uuid from 'uuid/v4'; 3 | import PropTypes from 'prop-types'; 4 | 5 | const Formulario = ({crearCita}) => { 6 | 7 | // Crear State de Citas 8 | const [cita, actualizarCita] = useState({ 9 | mascota: '', 10 | propietario: '', 11 | fecha: '', 12 | hora: '', 13 | sintomas: '' 14 | }); 15 | const [ error, actualizarError ] = useState(false) 16 | 17 | // Función que se ejecuta cada que el usuario escribe en un input 18 | const actualizarState = e => { 19 | actualizarCita({ 20 | ...cita, 21 | [e.target.name]: e.target.value 22 | }) 23 | } 24 | 25 | // Extraer los valores 26 | const { mascota, propietario, fecha, hora, sintomas } = cita; 27 | 28 | // Cuando el usuario presiona agregar cita 29 | const submitCita = e => { 30 | e.preventDefault(); 31 | 32 | // Validar 33 | if(mascota.trim() === '' || propietario.trim() === '' || fecha.trim() === '' || hora.trim() === '' || sintomas.trim() === '' ){ 34 | actualizarError(true); 35 | return; 36 | } 37 | // Eliminar el mensaje previo 38 | actualizarError(false); 39 | 40 | // Asignar un ID 41 | cita.id = uuid(); 42 | 43 | // Crear la cita 44 | crearCita(cita); 45 | 46 | // Reiniciar el form 47 | actualizarCita({ 48 | mascota: '', 49 | propietario: '', 50 | fecha: '', 51 | hora: '', 52 | sintomas: '' 53 | }) 54 | } 55 | 56 | return ( 57 | 58 |

Crear Cita

59 | 60 | { error ?

Todos los campos son obligatorios

: null } 61 | 62 |
65 | 66 | 74 | 75 | 76 | 84 | 85 | 86 | 93 | 94 | 95 | 102 | 103 | 104 | 110 | 111 | 115 |
116 |
117 | ); 118 | } 119 | 120 | Formulario.propTypes = { 121 | crearCita: PropTypes.func.isRequired 122 | } 123 | 124 | export default Formulario; -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | html { 2 | min-height: 100%; 3 | } 4 | body { 5 | margin: 0; 6 | padding: 0; 7 | font-family: sans-serif; 8 | background-image: linear-gradient(-225deg, #A445B2 0%, #D41872 52%, #FF0066 100%); 9 | min-height: 100%; 10 | padding-bottom: 5rem; 11 | } 12 | h1, h2 { 13 | color: white; 14 | padding: 3rem 0; 15 | text-align: center; 16 | 17 | text-transform: uppercase; 18 | 19 | font-family: 'Staatliches', cursive; 20 | letter-spacing: 1px; 21 | } 22 | .lista-citas .media { 23 | border-bottom: 1px solid #e1e1e1; 24 | padding-bottom: 3rem; 25 | } 26 | 27 | .lista-citas .media:last-of-type{ 28 | border-bottom: 0; 29 | } 30 | .lista-citas .media-body p { 31 | margin:0; 32 | } 33 | .lista-citas .media-body button { 34 | margin-top: 1rem!important; 35 | } 36 | .lista-citas .media-body span { 37 | font-weight: bold; 38 | } 39 | 40 | label { 41 | color: white; 42 | } 43 | 44 | input[type="date"], 45 | input[type="time"] { 46 | height: 38px; 47 | padding: 6px 10px; 48 | background-color: #fff; 49 | border: 1px solid #D1D1D1; 50 | border-radius: 4px; 51 | box-shadow: none; 52 | box-sizing: border-box; 53 | } 54 | 55 | .cita { 56 | padding: 2rem; 57 | background: white; 58 | border-bottom: 1px solid #e1e1e1; 59 | color: black; 60 | } 61 | 62 | .cita p { 63 | font-weight: bold; 64 | margin-bottom: .8rem; 65 | } 66 | .cita p span { 67 | font-weight: normal; 68 | 69 | } 70 | .cita:first-of-type { 71 | border-top-left-radius: 1rem; 72 | border-top-right-radius: 1rem; 73 | } 74 | .cita:last-of-type { 75 | border-bottom-left-radius: 1rem; 76 | border-bottom-right-radius: 1rem; 77 | } 78 | .button.eliminar, 79 | .button.eliminar:hover { 80 | background-color: #c10059; 81 | color: white; 82 | margin-top: 2rem; 83 | } 84 | 85 | .alerta-error { 86 | background-color: white; 87 | color: red; 88 | padding: 1rem; 89 | font-size: 2rem; 90 | text-transform: uppercase; 91 | text-align: center; 92 | font-family: 'Staatliches', cursive; 93 | } -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import * as serviceWorker from './serviceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | 9 | // If you want your app to work offline and load faster, you can change 10 | // unregister() to register() below. Note this comes with some pitfalls. 11 | // Learn more about service workers: https://bit.ly/CRA-PWA 12 | serviceWorker.unregister(); 13 | -------------------------------------------------------------------------------- /src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.1/8 is considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener('load', () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | 'This web app is being served cache-first by a service ' + 46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === 'installed') { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | 'New content is available and will be used when all ' + 74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log('Content is cached for offline use.'); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch(error => { 97 | console.error('Error during service worker registration:', error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl) 104 | .then(response => { 105 | // Ensure service worker exists, and that we really are getting a JS file. 106 | const contentType = response.headers.get('content-type'); 107 | if ( 108 | response.status === 404 || 109 | (contentType != null && contentType.indexOf('javascript') === -1) 110 | ) { 111 | // No service worker found. Probably a different app. Reload the page. 112 | navigator.serviceWorker.ready.then(registration => { 113 | registration.unregister().then(() => { 114 | window.location.reload(); 115 | }); 116 | }); 117 | } else { 118 | // Service worker found. Proceed as normal. 119 | registerValidSW(swUrl, config); 120 | } 121 | }) 122 | .catch(() => { 123 | console.log( 124 | 'No internet connection found. App is running in offline mode.' 125 | ); 126 | }); 127 | } 128 | 129 | export function unregister() { 130 | if ('serviceWorker' in navigator) { 131 | navigator.serviceWorker.ready.then(registration => { 132 | registration.unregister(); 133 | }); 134 | } 135 | } 136 | --------------------------------------------------------------------------------