build_app
This commit is contained in:
		
							parent
							
								
									0b5b65b8f3
								
							
						
					
					
						commit
						19ccc8b235
					
				| @ -69,6 +69,9 @@ public class BuilderService { | |||||||
| 		executeDump(true); | 		executeDump(true); | ||||||
| 
 | 
 | ||||||
| 		// ADD OTHER SERVICE | 		// ADD OTHER SERVICE | ||||||
|  | addCustomMenu( "Kirantest","Kirantest",  "Transcations");  | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| 		System.out.println("dashboard and menu inserted..."); | 		System.out.println("dashboard and menu inserted..."); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -0,0 +1,91 @@ | |||||||
|  | package com.realnet.basic1.Controllers; | ||||||
|  | import java.util.List; | ||||||
|  | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  |  import org.springframework.web.bind.annotation.*; | ||||||
|  | import org.springframework.web.multipart.MultipartFile; | ||||||
|  | import com.fasterxml.jackson.core.JsonProcessingException; | ||||||
|  | import org.springframework.web.bind.annotation.CrossOrigin; | ||||||
|  | import com.fasterxml.jackson.databind.JsonMappingException; | ||||||
|  | import com.realnet.config.EmailService; | ||||||
|  | import com.realnet.users.entity1.AppUser; | ||||||
|  | import com.realnet.users.service1.AppUserServiceImpl; | ||||||
|  | import com.fasterxml.jackson.databind.ObjectMapper; | ||||||
|  | import org.springframework.data.domain.*; | ||||||
|  | import com.realnet.fnd.response.EntityResponse; | ||||||
|  | import org.springframework.http.*; | ||||||
|  | import org.springframework.beans.factory.annotation.*; | ||||||
|  | import com.realnet.basic1.Entity.Kirantest; | ||||||
|  | import com.realnet.basic1.Services.KirantestService ; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | @RequestMapping(value = "/Kirantest") | ||||||
|  |  @CrossOrigin("*")  | ||||||
|  | @RestController | ||||||
|  | public class KirantestController { | ||||||
|  | 	@Autowired | ||||||
|  | 	private KirantestService Service; | ||||||
|  | 
 | ||||||
|  | @Value("${projectPath}") | ||||||
|  | 	private String projectPath; | ||||||
|  |   | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	@PostMapping("/Kirantest") | ||||||
|  | 		  public Kirantest Savedata(@RequestBody Kirantest data) { | ||||||
|  | 		Kirantest save = Service.Savedata(data)	; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 		System.out.println("data saved..." + save); | ||||||
|  | 
 | ||||||
|  |  return save; | ||||||
|  | 	  } | ||||||
|  | @PutMapping("/Kirantest/{id}") | ||||||
|  | 	public  Kirantest update(@RequestBody Kirantest data,@PathVariable Integer id ) { | ||||||
|  | 		Kirantest update = Service.update(data,id); | ||||||
|  | 		System.out.println("data update..." + update); | ||||||
|  | 		return update; | ||||||
|  | 	}	  | ||||||
|  | //	get all with pagination | ||||||
|  | 	@GetMapping("/Kirantest/getall/page") | ||||||
|  | 	public Page<Kirantest> getall(@RequestParam(value = "page", required = false) Integer page, | ||||||
|  | 			@RequestParam(value = "size", required = false) Integer size) { | ||||||
|  | 		Pageable paging = PageRequest.of(page, size); | ||||||
|  | 		Page<Kirantest> get = Service.getAllWithPagination(paging); | ||||||
|  | 
 | ||||||
|  | 		return get; | ||||||
|  | 
 | ||||||
|  | 	}	 | ||||||
|  | 	@GetMapping("/Kirantest") | ||||||
|  | 	public List<Kirantest> getdetails() { | ||||||
|  | 		 List<Kirantest> get = Service.getdetails();		 | ||||||
|  | 		return get; | ||||||
|  | } | ||||||
|  | // get all without authentication  | ||||||
|  | 
 | ||||||
|  | 	@GetMapping("/token/Kirantest") | ||||||
|  | 	public List<Kirantest> getallwioutsec() { | ||||||
|  | 		 List<Kirantest> get = Service.getdetails();		 | ||||||
|  | 		return get; | ||||||
|  | } | ||||||
|  | @GetMapping("/Kirantest/{id}") | ||||||
|  | 	public  Kirantest  getdetailsbyId(@PathVariable Integer id ) { | ||||||
|  | 		Kirantest  get = Service.getdetailsbyId(id); | ||||||
|  | 		return get; | ||||||
|  | 	} | ||||||
|  | @DeleteMapping("/Kirantest/{id}") | ||||||
|  | 	public  ResponseEntity<?> delete_by_id(@PathVariable Integer id ) { | ||||||
|  | 	Service.delete_by_id(id); | ||||||
|  | 			return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK); | ||||||
|  | 	 | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,91 @@ | |||||||
|  | package com.realnet.basic1.Controllers; | ||||||
|  | import java.util.List; | ||||||
|  | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  |  import org.springframework.web.bind.annotation.*; | ||||||
|  | import org.springframework.web.multipart.MultipartFile; | ||||||
|  | import com.fasterxml.jackson.core.JsonProcessingException; | ||||||
|  | import org.springframework.web.bind.annotation.CrossOrigin; | ||||||
|  | import com.fasterxml.jackson.databind.JsonMappingException; | ||||||
|  | import com.realnet.config.EmailService; | ||||||
|  | import com.realnet.users.entity1.AppUser; | ||||||
|  | import com.realnet.users.service1.AppUserServiceImpl; | ||||||
|  | import com.fasterxml.jackson.databind.ObjectMapper; | ||||||
|  | import org.springframework.data.domain.*; | ||||||
|  | import com.realnet.fnd.response.EntityResponse; | ||||||
|  | import org.springframework.http.*; | ||||||
|  | import org.springframework.beans.factory.annotation.*; | ||||||
|  | import com.realnet.basic1.Entity.Kirantest; | ||||||
|  | import com.realnet.basic1.Services.KirantestService ; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | @RequestMapping(value = "/token/Kirantest") | ||||||
|  |  @CrossOrigin("*")  | ||||||
|  | @RestController | ||||||
|  | public class tokenFree_KirantestController { | ||||||
|  | 	@Autowired | ||||||
|  | 	private KirantestService Service; | ||||||
|  | 
 | ||||||
|  | @Value("${projectPath}") | ||||||
|  | 	private String projectPath; | ||||||
|  |   | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	@PostMapping("/Kirantest") | ||||||
|  | 		  public Kirantest Savedata(@RequestBody Kirantest data) { | ||||||
|  | 		Kirantest save = Service.Savedata(data)	; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 		System.out.println("data saved..." + save); | ||||||
|  | 
 | ||||||
|  |  return save; | ||||||
|  | 	  } | ||||||
|  | @PutMapping("/Kirantest/{id}") | ||||||
|  | 	public  Kirantest update(@RequestBody Kirantest data,@PathVariable Integer id ) { | ||||||
|  | 		Kirantest update = Service.update(data,id); | ||||||
|  | 		System.out.println("data update..." + update); | ||||||
|  | 		return update; | ||||||
|  | 	}	  | ||||||
|  | //	get all with pagination | ||||||
|  | 	@GetMapping("/Kirantest/getall/page") | ||||||
|  | 	public Page<Kirantest> getall(@RequestParam(value = "page", required = false) Integer page, | ||||||
|  | 			@RequestParam(value = "size", required = false) Integer size) { | ||||||
|  | 		Pageable paging = PageRequest.of(page, size); | ||||||
|  | 		Page<Kirantest> get = Service.getAllWithPagination(paging); | ||||||
|  | 
 | ||||||
|  | 		return get; | ||||||
|  | 
 | ||||||
|  | 	}	 | ||||||
|  | 	@GetMapping("/Kirantest") | ||||||
|  | 	public List<Kirantest> getdetails() { | ||||||
|  | 		 List<Kirantest> get = Service.getdetails();		 | ||||||
|  | 		return get; | ||||||
|  | } | ||||||
|  | // get all without authentication  | ||||||
|  | 
 | ||||||
|  | 	@GetMapping("/token/Kirantest") | ||||||
|  | 	public List<Kirantest> getallwioutsec() { | ||||||
|  | 		 List<Kirantest> get = Service.getdetails();		 | ||||||
|  | 		return get; | ||||||
|  | } | ||||||
|  | @GetMapping("/Kirantest/{id}") | ||||||
|  | 	public  Kirantest  getdetailsbyId(@PathVariable Integer id ) { | ||||||
|  | 		Kirantest  get = Service.getdetailsbyId(id); | ||||||
|  | 		return get; | ||||||
|  | 	} | ||||||
|  | @DeleteMapping("/Kirantest/{id}") | ||||||
|  | 	public  ResponseEntity<?> delete_by_id(@PathVariable Integer id ) { | ||||||
|  | 	Service.delete_by_id(id); | ||||||
|  | 			return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK); | ||||||
|  | 	 | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,29 @@ | |||||||
|  | package com.realnet.basic1.Entity; | ||||||
|  |  import lombok.*; | ||||||
|  | import com.realnet.WhoColumn.Entity.Extension;  | ||||||
|  |  import javax.persistence.*; | ||||||
|  |  import java.time.LocalDateTime; | ||||||
|  |  import java.util.*; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |  @Entity  | ||||||
|  |  @Data | ||||||
|  |  public class    Kirantest extends Extension {  | ||||||
|  |  /** | ||||||
|  | 	 *  | ||||||
|  | 	 */ | ||||||
|  | 	private static final long serialVersionUID = 1L; | ||||||
|  | 
 | ||||||
|  |  @Id | ||||||
|  |  @GeneratedValue(strategy = GenerationType.IDENTITY) | ||||||
|  |  private Integer id; | ||||||
|  | 
 | ||||||
|  | private String  name; | ||||||
|  | 
 | ||||||
|  | @Column(length = 2000) | ||||||
|  | private String description; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,28 @@ | |||||||
|  | package com.realnet.basic1.Repository; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | import org.springframework.data.domain.Page; | ||||||
|  | import org.springframework.data.domain.Pageable; | ||||||
|  | import org.springframework.data.jpa.repository.JpaRepository; | ||||||
|  | import org.springframework.data.jpa.repository.Query; | ||||||
|  | 
 | ||||||
|  | import org.springframework.stereotype.Repository;  | ||||||
|  | import java.util.*; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   | ||||||
|  | 
 | ||||||
|  | import com.realnet.basic1.Entity.Kirantest; | ||||||
|  | 
 | ||||||
|  | @Repository | ||||||
|  | public interface  KirantestRepository  extends  JpaRepository<Kirantest, Integer>  {  | ||||||
|  | 
 | ||||||
|  | @Query(value = "select * from kirantest where  created_by=?1", nativeQuery = true) | ||||||
|  | 	List<Kirantest> findAll(Long creayedBy); | ||||||
|  | 
 | ||||||
|  | @Query(value = "select * from kirantest where  created_by=?1", nativeQuery = true) | ||||||
|  | 	Page<Kirantest> findAll(Pageable page, Long creayedBy); | ||||||
|  | } | ||||||
| @ -0,0 +1,83 @@ | |||||||
|  | package com.realnet.basic1.Services; | ||||||
|  | import com.realnet.basic1.Repository.KirantestRepository; | ||||||
|  | import com.realnet.basic1.Entity.Kirantest | ||||||
|  | ;import java.util.*; | ||||||
|  | 
 | ||||||
|  | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  | import com.realnet.SequenceGenerator.Service.SequenceService; | ||||||
|  | import org.springframework.data.domain.Page; | ||||||
|  | import com.realnet.realm.Entity.Realm; | ||||||
|  | import com.realnet.realm.Services.RealmService; | ||||||
|  | import org.springframework.data.domain.Pageable; | ||||||
|  | import org.springframework.http.*; | ||||||
|  | import com.realnet.users.service1.AppUserServiceImpl; | ||||||
|  | import com.realnet.users.entity1.AppUser; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	import org.springframework.stereotype.Service; | ||||||
|  | 
 | ||||||
|  | @Service | ||||||
|  |  public class KirantestService { | ||||||
|  | @Autowired | ||||||
|  | private KirantestRepository Repository; | ||||||
|  | 	@Autowired | ||||||
|  | 	private AppUserServiceImpl userService;  | ||||||
|  | @Autowired | ||||||
|  | 	private RealmService realmService; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | public Kirantest Savedata(Kirantest data) { | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	data.setUpdatedBy(getUser().getUserId()); | ||||||
|  | 		data.setCreatedBy(getUser().getUserId()); | ||||||
|  | 		data.setAccountId(getUser().getAccount().getAccount_id()); | ||||||
|  | Kirantest save = Repository.save(data); | ||||||
|  | 				return save;	 | ||||||
|  | 			} | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | //	get all with pagination | ||||||
|  | 	public Page<Kirantest> getAllWithPagination(Pageable page) { | ||||||
|  | 		return Repository.findAll(page, getUser().getUserId()); | ||||||
|  | 	}			 | ||||||
|  | public List<Kirantest> getdetails() {   | ||||||
|  | 		List<Realm> realm = realmService.findByUserId(getUser().getUserId()); | ||||||
|  | List<Kirantest> all = Repository.findAll(getUser().getUserId()); | ||||||
|  | 		 | ||||||
|  | 		return all ;		} | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | public Kirantest getdetailsbyId(Integer id) { | ||||||
|  | 	return Repository.findById(id).get(); | ||||||
|  | 			} | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	public void delete_by_id(Integer id) { | ||||||
|  |  Repository.deleteById(id); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | public Kirantest update(Kirantest data,Integer id) { | ||||||
|  | 	Kirantest old = Repository.findById(id).get(); | ||||||
|  | old.setName(data.getName()); | ||||||
|  | 
 | ||||||
|  | old.setDescription(data.getDescription()); | ||||||
|  | 
 | ||||||
|  | final Kirantest test = Repository.save(old); | ||||||
|  | 		data.setUpdatedBy(getUser().getUserId()); | ||||||
|  |   return test;}  | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |  public AppUser getUser() { | ||||||
|  | 		AppUser user = userService.getLoggedInUser(); | ||||||
|  | 		return user; | ||||||
|  | 
 | ||||||
|  | 	}} | ||||||
							
								
								
									
										2
									
								
								test45rm-da-d/authsec_mysql/mysql/wf_table/wf_table.sql
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										2
									
								
								test45rm-da-d/authsec_mysql/mysql/wf_table/wf_table.sql
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,2 @@ | |||||||
|  | CREATE TABLE da.Kirantest(id BIGINT NOT NULL AUTO_INCREMENT, description VARCHAR(400), name VARCHAR(400),  PRIMARY KEY (id)); | ||||||
|  | 
 | ||||||
| @ -1,3 +1,5 @@ | |||||||
|  | import Kirantest from "./components/BuilderComponents/basic1/Kirantest/Kirantest"; | ||||||
|  | 
 | ||||||
| import React from "react"; | import React from "react"; | ||||||
| import { SystemParameterProvider } from './context/SystemParameterContext'; | import { SystemParameterProvider } from './context/SystemParameterContext'; | ||||||
| import { | import { | ||||||
| @ -107,6 +109,9 @@ const App = () => { | |||||||
|               <Route path="profile" element={<Profile />} />   |               <Route path="profile" element={<Profile />} />   | ||||||
|             </Route> |             </Route> | ||||||
|             {/* buildercomponents */} |             {/* buildercomponents */} | ||||||
|  |         <Route path="/Kirantest" element={<Kirantest />} /> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -0,0 +1,501 @@ | |||||||
|  | import React, { useEffect, useState ,useRef } from "react"; | ||||||
|  | import axios from "axios"; | ||||||
|  | import { | ||||||
|  |   Button, | ||||||
|  |   Dialog, | ||||||
|  |   Autocomplete, | ||||||
|  |   DialogActions, | ||||||
|  |   DialogContent, | ||||||
|  |   DialogTitle, | ||||||
|  |   Snackbar, | ||||||
|  |   Alert, | ||||||
|  |   Typography, | ||||||
|  |   TextField, | ||||||
|  |   Table, | ||||||
|  |   TableBody, | ||||||
|  |  Switch, | ||||||
|  |   TableCell, | ||||||
|  |   TableContainer, | ||||||
|  |   TableHead, | ||||||
|  |   TableRow, | ||||||
|  |  CardMedia, | ||||||
|  |   Card, | ||||||
|  |  LinearProgress, | ||||||
|  | Grid, | ||||||
|  | Container, | ||||||
|  |   TablePagination, | ||||||
|  |   Paper, | ||||||
|  |   IconButton, | ||||||
|  |   InputAdornment | ||||||
|  | } from "@mui/material"; | ||||||
|  | import Radio from '@mui/material/Radio'; | ||||||
|  | import RadioGroup from '@mui/material/RadioGroup'; | ||||||
|  | import FormControlLabel from '@mui/material/FormControlLabel'; | ||||||
|  | import FormControl from '@mui/material/FormControl'; | ||||||
|  | import FormLabel from '@mui/material/FormLabel'; | ||||||
|  | 
 | ||||||
|  | import FormGroup from '@mui/material/FormGroup'; | ||||||
|  | import Checkbox from '@mui/material/Checkbox'; | ||||||
|  | 
 | ||||||
|  | import InputLabel from '@mui/material/InputLabel'; | ||||||
|  | import MenuItem from '@mui/material/MenuItem'; | ||||||
|  | import Select from '@mui/material/Select'; | ||||||
|  | 
 | ||||||
|  | import Box from '@mui/material/Box'; | ||||||
|  | import OutlinedInput from '@mui/material/OutlinedInput'; | ||||||
|  | import Chip from '@mui/material/Chip'; | ||||||
|  | 
 | ||||||
|  | import { makeStyles } from '@mui/styles'; | ||||||
|  | import { QRCode } from "react-qrcode-logo"; | ||||||
|  | import Barcode from "react-barcode"; | ||||||
|  |  import { ToastContainer, toast } from "react-toastify"; | ||||||
|  | import "react-toastify/dist/ReactToastify.css"; | ||||||
|  | import ReCAPTCHA from 'react-google-recaptcha'; | ||||||
|  |  import { getToken } from '../../../../utils/tokenService';import SearchIcon from '@mui/icons-material/Search'; | ||||||
|  | 
 | ||||||
|  | const FILE_API_URL = `${process.env.REACT_APP_API_BASE_URL}/FileUpload/Uploadeddocs`; | ||||||
|  | const API_URL = `${process.env.REACT_APP_API_BASE_URL}/Kirantest/Kirantest`; | ||||||
|  | const token = localStorage.getItem("authToken"); | ||||||
|  | // Custom styles using makeStyles
 | ||||||
|  | const useStyles = makeStyles((theme) => ({ | ||||||
|  |   tableHeader: { | ||||||
|  |     backgroundColor: "#000000", | ||||||
|  |     color: "#ffffff", | ||||||
|  |   }, | ||||||
|  |   searchContainer: { | ||||||
|  |     display: 'flex', | ||||||
|  |     alignItems: 'center', | ||||||
|  |     marginBottom: theme.spacing(2), | ||||||
|  |   }, | ||||||
|  |   searchInput: { | ||||||
|  |     marginRight: theme.spacing(2), | ||||||
|  |     flex: 1, | ||||||
|  |   }, | ||||||
|  |   tableContainer: { | ||||||
|  |     marginTop: theme.spacing(2), | ||||||
|  |   }, | ||||||
|  |   dialogContent: { | ||||||
|  |     display: 'flex', | ||||||
|  |     flexDirection: 'column', | ||||||
|  |     gap: theme.spacing(2), | ||||||
|  |   }, | ||||||
|  |   formControl: { | ||||||
|  |     marginBottom: theme.spacing(2), | ||||||
|  |   }, | ||||||
|  |   button: { | ||||||
|  |     margin: theme.spacing(1), | ||||||
|  |   }, | ||||||
|  | })); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | const EntityTable = () => { | ||||||
|  |   const classes = useStyles(); | ||||||
|  |   const [data, setData] = useState([]); | ||||||
|  |   const [filteredData, setFilteredData] = useState([]); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   const [newEntity, setNewEntity] = useState({ | ||||||
|  |     name: "", | ||||||
|  | 
 | ||||||
|  |     description: "", | ||||||
|  | 
 | ||||||
|  |   }); | ||||||
|  |   const [editEntity, setEditEntity] = useState(null); | ||||||
|  |   const [showEditModal, setShowEditModal] = useState(false); | ||||||
|  |   const [showAddModal, setShowAddModal] = useState(false); | ||||||
|  |   const [showDeleteModal, setShowDeleteModal] = useState(false); | ||||||
|  |   const [deleteEntityId, setDeleteEntityId] = useState(null); | ||||||
|  |   const [currentPage, setCurrentPage] = useState(0); | ||||||
|  |   const [itemsPerPage] = useState(5); // Adjust this value as needed
 | ||||||
|  |   const [searchQuery, setSearchQuery] = useState(""); | ||||||
|  |   const [openSnackbar, setOpenSnackbar] = useState(false); | ||||||
|  |   const [snackbarMessage, setSnackbarMessage] = useState(""); | ||||||
|  |   const [qrText, setQrText] = useState(""); | ||||||
|  |   const [showQrCode, setShowQrCode] = useState(false);  | ||||||
|  |   const qrCodeRef = useRef(); | ||||||
|  |   const [barcodeText, setBarcodeText] = useState("");  | ||||||
|  |   const barcodeRef = useRef(); | ||||||
|  |   const [showBarcode, setShowBarcode] = useState(false); | ||||||
|  |   const [captchaValue, setCaptchaValue] = useState(null); | ||||||
|  |   const [alertMessage, setAlertMessage] = useState(""); | ||||||
|  |   const [showPaymentOptions, setShowPaymentOptions] = useState(false); | ||||||
|  |   const [uploadProgress, setUploadProgress] = useState(0); | ||||||
|  |   const [serverData, setServerData] = useState([]); | ||||||
|  |   const [showValulistModal, setShowValulistModal] = useState(false); | ||||||
|  |   const [snackbarSeverity, setSnackbarSeverity] = useState("success"); | ||||||
|  | 
 | ||||||
|  |   const handlePageChange = (event, newPage) => { | ||||||
|  |     setCurrentPage(newPage); | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   useEffect(() => { | ||||||
|  |     fetchData(); | ||||||
|  |   }, []); | ||||||
|  | 
 | ||||||
|  |   useEffect(() => { | ||||||
|  |     handleSearch(); | ||||||
|  |   }, [searchQuery, data]); | ||||||
|  | 
 | ||||||
|  |   const fetchData = async () => { | ||||||
|  |     try { | ||||||
|  |  const token = getToken(); | ||||||
|  |       const response = await axios.get(API_URL, { | ||||||
|  |         headers: { Authorization: `Bearer ${token}` }, | ||||||
|  |       }); | ||||||
|  |       setData(response.data); | ||||||
|  |     } catch (error) { | ||||||
|  |       console.error("Error fetching data:", error); | ||||||
|  |     } | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   const handleDelete = async () => { | ||||||
|  |     try { | ||||||
|  |  const token = getToken(); | ||||||
|  |       await axios.delete(`${API_URL}/${deleteEntityId}`, { | ||||||
|  |         headers: { Authorization: `Bearer ${token}` }, | ||||||
|  |       }); | ||||||
|  |       fetchData(); | ||||||
|  |       setSnackbarMessage("Successfully deleted!"); | ||||||
|  |       setSnackbarSeverity("success"); | ||||||
|  |       setOpenSnackbar(true); | ||||||
|  |       setShowDeleteModal(false); | ||||||
|  |     } catch (error) { | ||||||
|  |       console.error("Error deleting data:", error); | ||||||
|  |       setSnackbarMessage("Failed to delete!"); | ||||||
|  |       setSnackbarSeverity("error"); | ||||||
|  |       setOpenSnackbar(true); | ||||||
|  |     } | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   const handleAdd = async () => { | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     try { | ||||||
|  |  const token = getToken(); | ||||||
|  |       await axios.post(API_URL, newEntity, { | ||||||
|  |         headers: { Authorization: `Bearer ${token}` }, | ||||||
|  |       }); | ||||||
|  |       fetchData(); | ||||||
|  |       setNewEntity({ | ||||||
|  |     name: "", | ||||||
|  | 
 | ||||||
|  |     description: "", | ||||||
|  | 
 | ||||||
|  |       }); | ||||||
|  |       setShowAddModal(false); | ||||||
|  |       setSnackbarMessage("Successfully added!"); | ||||||
|  |       setSnackbarSeverity("success"); | ||||||
|  |       setOpenSnackbar(true); | ||||||
|  |     } catch (error) { | ||||||
|  |       console.error("Error adding data:", error); | ||||||
|  |       setSnackbarMessage("Failed to add!"); | ||||||
|  |       setSnackbarSeverity("error"); | ||||||
|  |       setOpenSnackbar(true); | ||||||
|  |     } | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   const handleChange = (e) => { | ||||||
|  |     const { name, value } = e.target; | ||||||
|  |     setNewEntity({ ...newEntity, [name]: value }); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   const handleChangeCheckbox = (e) => { | ||||||
|  |     const { name, value, checked } = e.target; | ||||||
|  |     setNewEntity({ ...newEntity, [value]: checked }); | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  | const handleChangeSelectMulti = (e) => { | ||||||
|  |     const { name, value } = e.target; | ||||||
|  |     setNewEntity({ ...newEntity, [name]: String(value) }); | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   const handleEditChange = (e) => { | ||||||
|  |     const { name, value } = e.target; | ||||||
|  |     setEditEntity({ ...editEntity, [name]: value }); | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   const handleEdit = (entity) => { | ||||||
|  |     let requiredKeys = Object.keys(newEntity); | ||||||
|  |     let newObj = {}; | ||||||
|  |     requiredKeys.forEach((key) => { | ||||||
|  |       newObj[key] = entity[key]; | ||||||
|  |     }); | ||||||
|  |     setEditEntity(entity); | ||||||
|  |     setNewEntity(newObj); | ||||||
|  |     setShowEditModal(true); | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   const handleUpdate = async () => { | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     try { | ||||||
|  |  const token = getToken(); | ||||||
|  |       await axios.put(`${API_URL}/${editEntity.id}`, newEntity, { | ||||||
|  |         headers: { Authorization: `Bearer ${token}` }, | ||||||
|  |       }); | ||||||
|  |       fetchData(); | ||||||
|  |       setShowEditModal(false); | ||||||
|  |       setSnackbarMessage("Successfully updated!"); | ||||||
|  |       setSnackbarSeverity("success"); | ||||||
|  |       setOpenSnackbar(true); | ||||||
|  |     } catch (error) { | ||||||
|  |       console.error("Error updating data:", error); | ||||||
|  |       setSnackbarMessage("Failed to update!"); | ||||||
|  |       setSnackbarSeverity("error"); | ||||||
|  |       setOpenSnackbar(true); | ||||||
|  |     } | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   const handleSearch = () => { | ||||||
|  |     const filtered = data; | ||||||
|  |     setFilteredData(filtered); | ||||||
|  |  }; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   return ( | ||||||
|  |     <div className="container mt-5"> | ||||||
|  |       <Typography variant="h4" gutterBottom> | ||||||
|  |         Entity Table | ||||||
|  |       </Typography> | ||||||
|  |       <div className={classes.searchContainer}> | ||||||
|  |         <Button | ||||||
|  |           variant="contained" | ||||||
|  |           color="primary" | ||||||
|  |           onClick={() => { | ||||||
|  |             let emptyNewEntity = {}; | ||||||
|  |             Object.keys(newEntity).forEach((key) => { | ||||||
|  |               emptyNewEntity[key] = | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |  ""; | ||||||
|  |             }); | ||||||
|  |             setNewEntity(emptyNewEntity); | ||||||
|  |             setShowAddModal(true); | ||||||
|  |           }} | ||||||
|  |           className={classes.button} | ||||||
|  |         > | ||||||
|  |           Add Entity | ||||||
|  |         </Button> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |         <TextField | ||||||
|  |           className={classes.searchInput} | ||||||
|  |           label="Search" | ||||||
|  |           variant="outlined" | ||||||
|  |           size="small" | ||||||
|  |           value={searchQuery} | ||||||
|  |           onChange={(e) => setSearchQuery(e.target.value)} | ||||||
|  |           InputProps={{ | ||||||
|  |             endAdornment: ( | ||||||
|  |               <InputAdornment position="end"> | ||||||
|  |                 <IconButton> | ||||||
|  |                   <SearchIcon /> | ||||||
|  |                 </IconButton> | ||||||
|  |               </InputAdornment> | ||||||
|  |             ), | ||||||
|  |           }} | ||||||
|  |         /> | ||||||
|  |       </div> | ||||||
|  |       <TableContainer component={Paper} className={classes.tableContainer}> | ||||||
|  |         <Table> | ||||||
|  |           <TableHead> | ||||||
|  |             <TableRow > | ||||||
|  |   <th>name</th> | ||||||
|  | 
 | ||||||
|  |   <th>description</th> | ||||||
|  | 
 | ||||||
|  |             </TableRow> | ||||||
|  |           </TableHead> | ||||||
|  |           <TableBody> | ||||||
|  |             {filteredData.slice(currentPage * itemsPerPage, (currentPage + 1) * itemsPerPage).map((entity) => ( | ||||||
|  |               <TableRow key={entity.id}> | ||||||
|  | 
 | ||||||
|  |               <td>{entity.name}</td> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |               <td>{entity.description}</td> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |                 <TableCell> | ||||||
|  |                   <Button | ||||||
|  |                     variant="contained" | ||||||
|  |                     color="warning" | ||||||
|  |                     size="small" | ||||||
|  |                     className={classes.button} | ||||||
|  |                     onClick={() => handleEdit(entity)} | ||||||
|  |                   > | ||||||
|  |                     Update | ||||||
|  |                   </Button> | ||||||
|  |                   <Button | ||||||
|  |                     variant="contained" | ||||||
|  |                     color="error" | ||||||
|  |                     size="small" | ||||||
|  |                     className={classes.button} | ||||||
|  |                     onClick={() => { | ||||||
|  |                       setDeleteEntityId(entity.id); | ||||||
|  |                       setShowDeleteModal(true); | ||||||
|  |                     }} | ||||||
|  |                   > | ||||||
|  |                     Delete | ||||||
|  |                   </Button> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |                 </TableCell> | ||||||
|  |               </TableRow> | ||||||
|  |             ))} | ||||||
|  |           </TableBody> | ||||||
|  |         </Table> | ||||||
|  |       </TableContainer> | ||||||
|  |       <TablePagination | ||||||
|  |         rowsPerPageOptions={[5, 10, 25]} | ||||||
|  |         component="div" | ||||||
|  |         count={filteredData.length} | ||||||
|  |         rowsPerPage={itemsPerPage} | ||||||
|  |         page={currentPage} | ||||||
|  |         onPageChange={handlePageChange} | ||||||
|  |       /> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |       <Dialog open={showEditModal} onClose={() => setShowEditModal(false)}> | ||||||
|  |         <DialogTitle>Edit Entity</DialogTitle> | ||||||
|  |         <DialogContent className={classes.dialogContent}> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | <TextField | ||||||
|  |           fullWidth | ||||||
|  |           margin="normal" | ||||||
|  |           label="Name" | ||||||
|  |           variant="outlined" | ||||||
|  |           name="name" | ||||||
|  |           value={newEntity.name} | ||||||
|  |           onChange={handleChange} | ||||||
|  |           required | ||||||
|  |         /> | ||||||
|  | 
 | ||||||
|  | <TextField | ||||||
|  |           fullWidth | ||||||
|  |           margin="normal" | ||||||
|  |           label="Description" | ||||||
|  |           variant="outlined" | ||||||
|  |           name="description" | ||||||
|  |           value={newEntity.description} | ||||||
|  |           onChange={handleChange} | ||||||
|  |           multiline | ||||||
|  |           rows={4} | ||||||
|  |           required | ||||||
|  |         /> | ||||||
|  | 
 | ||||||
|  |         </DialogContent> | ||||||
|  |         <DialogActions> | ||||||
|  |           <Button onClick={() => setShowEditModal(false)} color="primary"> | ||||||
|  |             Cancel | ||||||
|  |           </Button> | ||||||
|  |           <Button onClick={handleUpdate} color="primary"> | ||||||
|  |             Update | ||||||
|  |           </Button> | ||||||
|  |         </DialogActions> | ||||||
|  |       </Dialog> | ||||||
|  |       <Dialog open={showAddModal} onClose={() => setShowAddModal(false)}> | ||||||
|  |         <DialogTitle>Add Entity</DialogTitle> | ||||||
|  |         <DialogContent className={classes.dialogContent}> | ||||||
|  | <TextField | ||||||
|  |           fullWidth | ||||||
|  |           margin="normal" | ||||||
|  |           label="Name" | ||||||
|  |           variant="outlined" | ||||||
|  |           name="name" | ||||||
|  |           value={newEntity.name} | ||||||
|  |           onChange={handleChange} | ||||||
|  |           required | ||||||
|  |         /> | ||||||
|  | 
 | ||||||
|  | <TextField | ||||||
|  |           fullWidth | ||||||
|  |           margin="normal" | ||||||
|  |           label="Description" | ||||||
|  |           variant="outlined" | ||||||
|  |           name="description" | ||||||
|  |           value={newEntity.description} | ||||||
|  |           onChange={handleChange} | ||||||
|  |           multiline | ||||||
|  |           rows={4} | ||||||
|  |           required | ||||||
|  |         /> | ||||||
|  | 
 | ||||||
|  |   | ||||||
|  | 
 | ||||||
|  |   | ||||||
|  | 
 | ||||||
|  |         </DialogContent> | ||||||
|  |         <DialogActions> | ||||||
|  |           <Button onClick={() => setShowAddModal(false)} color="primary"> | ||||||
|  |             Cancel | ||||||
|  |           </Button> | ||||||
|  |           <Button onClick={handleAdd | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | } color="primary"> | ||||||
|  |             Add | ||||||
|  |           </Button> | ||||||
|  |         </DialogActions> | ||||||
|  |       </Dialog> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |       <Dialog open={showDeleteModal} onClose={() => setShowDeleteModal(false)}> | ||||||
|  |         <DialogTitle>Confirm Delete</DialogTitle> | ||||||
|  |         <DialogContent> | ||||||
|  |           <Typography>Are you sure you want to delete this entity?</Typography> | ||||||
|  |         </DialogContent> | ||||||
|  |         <DialogActions> | ||||||
|  |           <Button onClick={() => setShowDeleteModal(false)} color="primary"> | ||||||
|  |             Cancel | ||||||
|  |           </Button> | ||||||
|  |           <Button onClick={handleDelete} color="primary"> | ||||||
|  |             Delete | ||||||
|  |           </Button> | ||||||
|  |         </DialogActions> | ||||||
|  |       </Dialog> | ||||||
|  |       <Snackbar | ||||||
|  |         open={openSnackbar} | ||||||
|  |         autoHideDuration={6000} | ||||||
|  |         onClose={() => setOpenSnackbar(false)} | ||||||
|  |       > | ||||||
|  |         <Alert onClose={() => setOpenSnackbar(false)} severity={snackbarSeverity}> | ||||||
|  |           {snackbarMessage} | ||||||
|  |         </Alert> | ||||||
|  |       </Snackbar> | ||||||
|  |     </div> | ||||||
|  |   ); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | export default EntityTable; | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user