Commit f5e7162f authored by RusiraPathum's avatar RusiraPathum

first commit

parents
Pipeline #4118 failed with stages
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
FROM node:15-alpine as builder
WORKDIR /app
RUN apk update
RUN apk add yarn
COPY . .
RUN yarn
RUN yarn run build
FROM node:15-alpine
RUN yarn global add serve
WORKDIR /app
COPY --from=builder /app/build .
EXPOSE 4300
CMD ["serve", "-p", "4300", "-s", "."]
\ No newline at end of file
# Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `yarn start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.
### `yarn test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `yarn build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `yarn eject`
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
### Analyzing the Bundle Size
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
### Making a Progressive Web App
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
### Advanced Configuration
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
### Deployment
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
### `yarn build` fails to minify
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
This diff is collapsed.
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"axios": "^0.21.1",
"react": "^17.0.2",
"react-bootstrap": "^1.6.1",
"react-confirm-alert": "^2.7.0",
"react-dom": "^17.0.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>Student Managment System</title>
<!-- Latest compiled and minified CSS -->
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
/>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</html>
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
.App {
/* text-align: center; */
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
import "./App.css";
// import CounterClass from "./components/CounterClass";
// import CounterFunction from "./components/CounterFunction";
import Header from "./components/Header";
import AddStudent from "./components/AddStudent";
import { AllStudent } from "./components/AllStudent";
import EditStudent from "./components/EditStudent";
import { BrowserRouter as Router, Route } from "react-router-dom";
function App() {
return (
<Router>
<div className="App">
<Header />
{/* <AddStudent /> */}
<Route path="/" exact component={AllStudent}/>
<Route path="/add" exact component={AddStudent} />
<Route path="/edit/:id" exact component={EditStudent} />
</div>
</Router>
);
}
export default App;
import React, { useState } from "react";
import axios from "axios";
export default function AddStudent() {
let [name, setName] = useState("");
let [age, setAge] = useState("");
let [gender, setGender] = useState("");
function sendData(e) {
e.preventDefault();
const newStudent = {
name,
age,
gender,
};
// console.log(newStudent);
axios
.post("http://localhost:8070/student/add", newStudent)
.then(() => {
alert("Student Added");
document.getElementById('name').value = "";
document.getElementById('age').value = "";
document.getElementById('gender').value = "";
})
.catch((err) => {
alert(err);
});
}
return (
<div className="container mt-5">
<h1 className="mb-3">Student Add</h1><hr></hr>
<form onSubmit={sendData}>
<div className="form-group">
<label>Student Name</label>
<input
type="text"
className="form-control"
id="name"
onChange={(e) => {
setName(e.target.value);
}}
></input>
</div>
<div className="form-group">
<label>Age</label>
<input
type="number"
className="form-control"
id="age"
onChange={(e) => {
setAge(e.target.value);
}}
></input>
</div>
<div className="form-group">
<label>Gender</label>
<input
type="text"
className="form-control"
id="gender"
onChange={(e) => {
setGender(e.target.value);
}}
></input>
</div>
<button type="submit" className="btn btn-primary">
Submit
</button>
</form>
</div>
//onClick={e => sendData()}
);
}
import React, { useState, useEffect } from "react";
import axois from "axios";
import { confirmAlert } from "react-confirm-alert";
import "react-confirm-alert/src/react-confirm-alert.css";
import { Modal, Button } from 'react-bootstrap';
import { Link } from "react-router-dom";
export function AllStudent() {
const [students, setStudents] = useState([]);
useEffect(() => {
function getStudent() {
axois
.get("http://localhost:8070/student/")
.then((res) => {
setStudents(res.data);
// console.log(res);
})
.catch((err) => {
alert(err.message);
});
}
getStudent();
}, []);
function deleteStuudent(id) {
confirmAlert({
customUI: ({ onClose }) => {
return (
<div className="custom-ui text-center">
<h1 className="text-center">Are you sure?</h1>
<p className="text-center">You want to delete this Student?</p>
<button className="btn btn-primary mr-3" onClick={onClose}>
No
</button>
<button
className="btn btn-danger"
onClick={() => {
// this.handleClickDelete();
axois
.delete(`http://localhost:8070/student/delete/${id}`)
.then(() => {
alert("Successfully Deleted");
// <div className="alert alert-success" id="success-alert" role="alert">
// Successfully Deleted
// </div>;
// document.getElementById("success-alert")
// .fadeTo(2000, 500)
// .slideUp(500, function () {
// document.getElementById("success-alert").slideUp(500);
// });
window.location.reload();
})
.catch((err) => {
alert(err.message);
});
onClose();
}}
>
Yes, Delete it!
</button>
</div>
);
},
});
}
return (
<div className="container mt-5">
<h1>All Student Details</h1><hr></hr>
<div>
<table className="table">
<thead className="thead-dark">
<tr>
<th scope="col">Name</th>
<th scope="col">Age</th>
<th scope="col">Gender</th>
<th scope="col">Control</th>
</tr>
</thead>
<tbody>
{students.length > 0 &&
students.map((item, index) => (
<tr key={index}>
<th>{item.name}</th>
<td>{item.age}</td>
<td>{item.gender}</td>
<td>
<Link
className="btn btn-success mr-3" to={`/edit/${item._id}`}>
Edit
</Link>
<button
data-toggle="modal"
data-target="#exampleModal"
className="btn btn-danger"
onClick={() => {
deleteStuudent(item._id);
}}
>
Delete
</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
);
}
import React, { Component } from "react";
class CounterClass extends React.Component {
constructor() {
super();
//function bind
this.increment = this.increment.bind(this);
//state object
this.state = {
number: 0,
};
}
//increment funtion
increment(){
this.setState({
number: this.state.number + 1
//number: ++this.state.number;
})
}
render() {
return (
<div>
<h3>Class Component</h3>
<h1>Counter = {this.state.number}</h1>
<button className="btn btn-success" onClick={this.increment}>Increment</button>
</div>
);
}
}
//expotr
export default CounterClass;
import React, { useState } from "react";
//component ekak
function CounterFunction(){
//state variables
let [number, setNumber] = useState(0);
function increment(){
setNumber(++number);
}
return(
<div>
<h3>Functional Component</h3>
<h1>Counter = {number}</h1>
<button className="btn btn-success" onClick={e => increment()}>Increment</button>
</div>
)
}
export default CounterFunction;
\ No newline at end of file
import React, { useState, useEffect } from "react";
import axios from "axios";
import { useParams } from "react-router-dom";
function EditStudent() {
let sid = useParams().id;
// console.log(sid);
const [students, setStudents] = useState([]);
let studentId1 = "";
let name1 = "";
let age1 = "";
let gender1 = "";
useEffect(() => {
function getSingelStudent() {
axios
.get(`http://localhost:8070/student/get/` + sid)
.then((res) => {
setStudents(res.data);
studentId1 = res.data._id;
name1 = res.data.name;
age1 = res.data.age;
gender1 = res.data.gender;
// console.log(age1);
document.getElementById("studentId").value = studentId1;
document.getElementById("name").value = name1;
document.getElementById("age").value = age1;
document.getElementById("gender").value = gender1;
})
.catch((err) => {
alert(err.message);
});
}
getSingelStudent();
}, []);
// let [name, setName] = useState("");
// let [age, setAge] = useState("");
// let [gender, setGender] = useState("");
// alert(name);
function updateData(e) {
e.preventDefault();
let id = document.getElementById("studentId").value;
let name = document.getElementById("name").value;
let age = document.getElementById("age").value;
let gender = document.getElementById("gender").value;
const newStudent = {
name,
age,
gender,
};
// console.log(newStudent);
axios
.put(`http://localhost:8070/student/update/`+id, newStudent)
.then(() => {
alert("Student Updated");
document.getElementById("studentId").value = "";
document.getElementById("name").value = "";
document.getElementById("age").value = "";
document.getElementById("gender").value = "";
})
.catch((err) => {
alert(err);
});
}
return (
<div className="container mt-5">
<h1 className="mb-3">Student Update</h1>
<hr></hr>
<form onSubmit={updateData}>
<div className="form-group">
<input
hidden
type="text"
className="form-control"
id="studentId"
// onChange={(e) => {
// setName(e.target.value);
// }}
></input>
</div>
<div className="form-group">
<label>Student Name</label>
<input
type="text"
className="form-control"
id="name"
// onChange={(e) => {
// setName(e.target.value);
// }}
></input>
</div>
<div className="form-group">
<label>Age</label>
<input
type="number"
className="form-control"
id="age"
// onChange={(e) => {
// setAge(e.target.value);
// }}
></input>
</div>
<div className="form-group">
<label>Gender</label>
<input
type="text"
className="form-control"
id="gender"
// onChange={(e) => {
// setGender(e.target.value);
// }}
></input>
</div>
<button type="submit" className="btn btn-primary">
Submit
</button>
</form>
</div>
);
}
export default EditStudent;
import React from "react";
import { Link } from "react-router-dom";
function Header() {
return (
<nav className="navbar navbar-expand-lg navbar-dark bg-dark">
<a className="navbar-brand" href="/">
Navbar
</a>
<button
className="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#navbarNavAltMarkup"
aria-controls="navbarNavAltMarkup"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span className="navbar-toggler-icon"></span>
</button>
<div className="collapse navbar-collapse" id="navbarNavAltMarkup">
<div className="navbar-nav">
<Link className="nav-link active" to="/">
Home <span className="sr-only">(current)</span>
</Link>
<Link className="nav-link" to="/add">
Create Student
</Link>
</div>
</div>
</nav>
);
}
export default Header;
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment