Dashboard Category Component
import React from 'react'; import './dcategory.scss'; import CKEditor from '../dckeditor/dckeditor.js'; import tool from '../../tool.js'; class DCategory extends React.Component{ constructor(props){ super(props); this.state = {date: false, time: false}; this.getDateTime(); } getDateTime = async () => { const dateTime = await tool.fetchAPI('/admin/category/api'); this.setState({date: dateTime.date, time: dateTime.time}); } render(){ return( <div className="DCategory"> <CKEditor /> <form className='category-form' > <input type='submit' /> <input type='text' name='category-name' placeholder='category name' required='required' /> <input type='date' value={this.state.date} name='date' required='required' /> <input type='time' value={this.state.time} name='time' required='required' /> </form> </div> ); } } export default DCategory;
.DCategory{ width: 80%; float: right; padding-left: 20px; border-left: 1px solid lightgrey; text-align: left; .category-form{ display: grid; grid-template-columns: 10% auto 25% 25%; input{ font: 14px/1.5 VidaLoka; padding: 0 10px; } input[type=date], input[type=time]{ text-align: center; } } }
// routes/admin.js const e = require('express'); var express = require('express'); var router = express.Router(); router.post('/login', function(req, res, next){ const login = require('../controllers/login'); login.postLogin(req, res); }); router.get('/logged', function(req, res, next){ const login = require('../controllers/login'); login.checkLogin(req, res); }); router.get('/logout', function(req, res, next){ const login = require('../controllers/login'); login.logOut(req, res); }); router.get('/category/api', function(req, res, next){ if(req.session.user){ const category = require('../controllers/category'); category.getDateTime(req, res); }else{ redirect('/login'); } }); module.exports = router;
// controllers/category.js class Category{ getDateTime(req, res){ const today = new Date(); const date = today.toLocaleDateString('fr-CA'); const time = today.toLocaleTimeString('it-IT'); res.json({date: date, time: time}); } }//end class module.exports = new Category();
GitHub: "https://github.com/Sokhavuth/emultimedia
Heroku: https://khmerweb-emultimedia.herokuapp.com/
Comments
Post a Comment