Problems with Bootstrap HTML template in React - reactjs

I've received this template https://themeforest.net/item/light-admin-clean-bootstrap-dashboard-html-template/19760124 to implement an admin dashboard.
I started it in Angular 8, but I must move it to React.
The problem is that I'm not being able to get it working correctly in React.
In Angular, I setup like this inside angular.json:
"styles": [
"node_modules/select2/dist/css/select2.css",
"node_modules/bootstrap-daterangepicker/daterangepicker.css",
"node_modules/dropzone/dist/dropzone.css",
"node_modules/datatables.net-bs/css/dataTables.bootstrap.css",
"node_modules/fullcalendar/dist/fullcalendar.min.css",
"node_modules/perfect-scrollbar/dist/css/perfect-scrollbar.min.css",
"node_modules/slick-carousel/slick/slick.css",
"src/css/main.css",
"src/css/styles.css"
],
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/popper.js/dist/umd/popper.min.js",
"node_modules/moment/moment.js",
"node_modules/chart.js/dist/Chart.min.js",
"node_modules/select2/dist/js/select2.full.min.js",
"node_modules/jquery-bar-rating/dist/jquery.barrating.min.js",
"node_modules/ckeditor/ckeditor.js",
"node_modules/bootstrap-validator/dist/validator.min.js",
"node_modules/bootstrap-daterangepicker/daterangepicker.js",
"node_modules/ion-rangeslider/js/ion.rangeSlider.min.js",
"node_modules/dropzone/dist/dropzone.js",
"node_modules/editable-table/dist/editable-table.js",
"node_modules/datatables.net/js/jquery.dataTables.js",
"node_modules/datatables.net-bs/js/dataTables.bootstrap.js",
"node_modules/fullcalendar/dist/fullcalendar.min.js",
"node_modules/perfect-scrollbar/dist/js/perfect-scrollbar.jquery.min.js",
"node_modules/tether/dist/js/tether.min.js",
"node_modules/slick-carousel/slick/slick.min.js",
"node_modules/bootstrap/js/dist/util.js",
"node_modules/bootstrap/js/dist/alert.js",
"node_modules/bootstrap/js/dist/button.js",
"node_modules/bootstrap/js/dist/carousel.js",
"node_modules/bootstrap/js/dist/collapse.js",
"node_modules/bootstrap/js/dist/dropdown.js",
"node_modules/bootstrap/js/dist/modal.js",
"node_modules/bootstrap/js/dist/tab.js",
"node_modules/bootstrap/js/dist/tooltip.js",
"node_modules/bootstrap/js/dist/popover.js",
"src/js/demo_customizer.js",
"src/js/main.js"
]
},
It worked like a charm. But in React I'm getting a lot of warnings and errors.
I tried this inside App.tsx:
import 'select2/dist/css/select2.css'
import 'bootstrap-daterangepicker/daterangepicker.css'
import 'dropzone/dist/dropzone.css'
import 'datatables.net-bs/css/dataTables.bootstrap.css'
import 'fullcalendar/dist/fullcalendar.min.css'
import 'perfect-scrollbar/dist/css/perfect-scrollbar.min.css'
import 'slick-carousel/slick/slick.css'
import './assets/css/main.css'
import './assets/css/styles.css'
import 'jquery'
import 'popper.js'
import 'moment'
import 'chart.js'
import 'select2'
import 'jquery-bar-rating'
import 'ckeditor'
import 'bootstrap-validator'
import 'bootstrap-daterangepicker'
import 'ion-rangeslider'
import 'dropzone'
import 'editable-table'
import 'datatables.net'
import 'datatables.net-bs'
import 'fullcalendar'
import 'perfect-scrollbar'
import 'tether'
import 'slick-carousel'
import 'bootstrap'
import 'dragula'
import './assets/js/demo_customizer.js'
import './assets/js/main.js'
import React from 'react';
import Routes from './routes'
const App: React.FC = () => <Routes/>
export default App;
But I'm getting a lot of error, like:
ReferenceError: jQuery is not defined
./node_modules/bootstrap-validator/js/validator.js
... and so on.
Any idea how I can get this template working on React?

Related

Cannot read properties of undefined (reading 'React')

I have an app that works well locally. But on production, I am getting this error.
enter image description here
enter image description here
I thought it is related to webpack but could not find any clue. I am stuck with that.
import React from 'react';
import ReactDOM from 'react-dom';
import moment from 'moment';
import * as styled from 'styled-components';
import NotificationContext from 'og-merchant-portal-react-library/lib/NotificationContext/NotificationContext';
import FetchContext from 'og-merchant-portal-react-library/lib/FetchContext';
import { UserInfoContext } from 'og-merchant-portal-react-library';
import App from './App';
import { unregister } from './serviceWorker';
window.IngenicoLib = {
React,
ReactDOM,
moment,
NotificationContext,
FetchContext,
UserInfoContext,
'styled-components': styled,
};

Gatsby - how to use third party dependencies?

I've to use bootstrap-select, bootstrap, jquery, popper, isotope, wow and a script file that uses all these libs with Gatsby. I did like this in layout.js:
import React from "react"
import { StaticQuery, graphql } from 'gatsby'
import "bootstrap/dist/css/bootstrap.min.css"
import "./vendors/themify-icon/themify-icons.css"
import "font-awesome/css/font-awesome.min.css"
import "./vendors/flaticon/flaticon.css"
import "animate.css/animate.min.css"
import "./vendors/magnify-pop/magnific-popup.css"
import "./layout.css"
import "./responsive.css"
import "jquery/dist/jquery.min.js"
import "popper.js/dist/popper"
import "bootstrap/dist/js/bootstrap.min.js"
import "bootstrap-select/dist/js/bootstrap-select.min.js"
import "wowjs/dist/wow.min.js"
import "jquery.scroll-parallax/dist/js/jquery.scrollParallax.js"
import "./vendors/isotope/isotope-min.js"
import "./vendors/magnify-pop/jquery.magnific-popup.min.js"
import Loader from "./loader"
import Header from "./header"
import Breadcrumb from "./breadcrumb"
Is this a correct way to import all these dependencies ?
During gatsby develop I am not sure it works or not but I am not getting any errors. During gatsby build it failed. So, I copied all these files to static and build passed.
Then I checked for all these files in common.js but not a single file code is there. How do I use all these dependencies with Gatsby ?

Using import relative path in React

I am trying to import Dashboard from LoginPage component.
I tried
import Dashboard from './scenes/Dashboard
import Dashboard from './Dashboard
import Dashboard from '../../Dashboard
but they all didn't work.
What is the correct way to import it?
If the component name is 'DashboardComponent' exported using export default, you can import by,
import DashboardComponent from '../Dashboard/DashboardComponent'
if it is not default export, it can be imported using {} as,
import {DashboardComponent} from '../Dashboard/DashboardComponent'

React Import looks in the wrong directory

For some reason when I try to import one particular module, react refuses to look in the correct directory (./node_modules/). Instead it looks in the ./src/ directory and throws this error:
/src/App.js
Module not found: Can't resolve 'react-d3gantt' in '/Users/RAVEN/Desktop/frontend/materialui/material/src'
All of my other modules are imported correctly. What is it about this one in particular?
Here is my code:
import React, { Component } from 'react';
import { DefaultButton, CompoundButton } from 'office-ui-fabric-react/lib/Button';
import { Image } from 'office-ui-fabric-react/lib/Image';
import { Icon } from 'office-ui-fabric-react/lib/Icon';
import { GanttChart } from "react-d3gantt";
import OilSite from './components/oilsite';
import BigButton from './components/bigButton';
import LeftNav from './components/leftNav';
import './index.css';
Edit: I used Create-React-App, in case this is relevant to my set up.

Observable.from() in angular 2 tests - errors inside test method

I have to use an Observable in my tests and this little code:
it("should emit values", () => {
const f = Observable.of([1, 3, 5]);
f.subscribe(d => console.log(d));
});
gives the following error:
TypeError: undefined is not a constructor (evaluating 'Observable_1.Observable.of([1, 3, 5])')
But if I put these 2 lines of code inside a component (say, in ngOnInit) I see emitted values and no error. I wonder if this me or angular 2 has some issues with its testing codebase?
Just in case, these are all imports I use in this particular test file:
import {
it,
inject,
injectAsync,
beforeEachProviders,
TestComponentBuilder
} from 'angular2/testing';
import {ComponentFixture, dispatchEvent, fakeAsync, tick} from 'angular2/testing_internal';
import {provide, bind} from 'angular2/core';
import {FormBuilder} from 'angular2/common';
import {By} from 'angular2/platform/browser';
import {Observable} from 'rxjs/Observable';
import {ArrayObservable} from 'rxjs/observable/fromArray';
import {Subject} from 'rxjs/Subject';
import {BehaviorSubject} from 'rxjs/subject/BehaviorSubject';
import {SpyLocation} from 'angular2/src/mock/location_mock';
import {RootRouter} from 'angular2/src/router/router';
import {Router, RouterOutlet, RouterLink, RouteParams, ComponentInstruction, RouteData, Location, ROUTER_PRIMARY_COMPONENT} from 'angular2/router';
import {
RouteConfig,
Route,
AuxRoute,
AsyncRoute,
Redirect
} from 'angular2/src/router/route_config_decorator';
import {RouteRegistry} from 'angular2/src/router/route_registry';
import {DirectiveResolver} from 'angular2/src/core/linker/directive_resolver';
import {ResolvedInstruction} from 'angular2/src/router/instruction';
Have you tried changing import {Observable} from 'rxjs/Observable'; to import {Observable} from 'rxjs/Rx'; ? It might help because importing it this way will get you all the operations which you might use in your component.

Resources