Blank page in Firebase hosting with paramter in url reactjs - react-router

I use Firebase hosting in combination with ReactJS. if I include a parameter in the url on my localhost, this works fine. The configuration is as follows:
Only when I deploy it to the firebase hosting I get a white blank page. such as eg:
in my routes.js:
{
path: "/ontbijt-betaling/:id",
layout: ModalLayout,
exact: false,
component: PayBreakfastView
},
In my view:
import React from "react";
import { Container, Row, Col } from "shards-react";
import PayBreakfastComponent from "../../components/Frontend/PayBreakfastComponent";
import FooterView from "../Footer";
import HeaderView from "../Header";
const PayBreakfastView = (props) => (
<Container fluid >
<HeaderView />
<PayBreakfastComponent id={props.match.params.id}/>
<FooterView />
</Container>
);
export default PayBreakfastView;
and the component:
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { Link } from 'react-router-dom';
import { Row, Col, Card, CardHeader, CardBody, Button } from "shards-react";
import Firebase from 'firebase';
class PayBreakfastComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
name:'',
mail:'',
shortDesc:'',
payment:[]
};
}
componentWillMount(){
console.log('mount')
let tempPayment = Firebase.database().ref('/clients/-uhfwoebfwioudb/content/temp-payments/'+this.props.id);
tempPayment.on('value', snapshot => {
let state = snapshot.val();
this.setState({
payment: state,
get: true
})
localStorage.setItem('name',state.name);
localStorage.setItem('mail',state.email);
localStorage.setItem('date',state.date);
localStorage.setItem('phone',state.phone);
localStorage.setItem('adres',state.adres);
localStorage.setItem('postal',state.zip);
localStorage.setItem('city',state.city);
localStorage.setItem('bookingID', state.bookingsnumber)
localStorage.setItem('amount',state.amount);
localStorage.setItem('shippingCost',state.shippingCost);
localStorage.setItem('unitPrice',state.unitPrice);
localStorage.setItem('total',state.totalPrice);
console.log(state.email)
})
}
payOrder(){
/* var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://app.biejanssen.nl/paymentBreak');
xhr.setRequestHeader("Content-Type", "application/json");
let data ={
totalPrice: this.state.payment.totalPrice,
nameClient: this.state.payment.name,
emailClient: this.state.payment.email,
}
xhr.send(JSON.stringify(data));
xhr.onload = () => {
console.log("status is:"+xhr.responseURL);
window.location.href=xhr.responseURL;
};*/
}
render() {
return (
<div className="home-page">
<Row className="contact-row">
<Col sm={12} className="contact-colum">
<h2>Ontbijt betalen</h2>
</Col>
</Row>
<Row>
<Col sm={3}></Col>
<Col sm={6} className="frontend-table">
<h2>Uw bestel overzicht</h2>
<form method="post" action={"https://app.biejanssen.nl/paymentBreak"} id="hook-form" >
<table>
<tr>
<td><span className="total-fat">Order nummer</span></td>
<td>{this.state.payment.bookingsnumber} <input type="text" value={this.state.payment.bookingsnumber} hidden/></td>
</tr>
<tr>
<td><span className="total-fat">Omschrijving</span></td>
<td>Ontbijt</td>
</tr>
<tr>
<td><span className="total-fat">Uw naam</span></td>
<td>{this.state.payment.name} <input type="text" name="nameClient" value={this.state.payment.name} hidden/></td>
</tr>
<tr>
<td><span className="total-fat">Uw e-mail</span></td>
<td>{this.state.payment.email} <input type="text" name="emailClient" value={this.state.payment.email} hidden/></td>
</tr>
<tr>
<td><span className="total-fat">Uw telefoonnummer</span></td>
<td>{this.state.payment.phone}</td>
</tr>
<tr>
<td><span className="total-fat">Aflever datum</span></td>
<td>{this.state.payment.date}</td>
</tr>
<tr>
<td><span className="total-fat">Aflever adres</span></td>
<td>{this.state.payment.adres}, {this.state.payment.zip}, {this.state.payment.city}</td>
</tr>
<tr>
<td><span className="total-fat">Aantal ontbijtjes</span></td>
<td>{this.state.payment.amount}</td>
</tr>
<tr>
<td><span className="total-fat">Prijs per ontbijt</span></td>
<td>€ {this.state.payment.unitPrice}</td>
</tr>
<tr>
<td><span className="total-fat">Bezorgkosten ontbijt</span></td>
<td>€ {this.state.payment.shippingCost}</td>
</tr>
<tr>
<td><span className="total-oder">Totaal</span></td>
<td><span className="total-oder">€ {this.state.payment.totalPrice} <input type="text" name="totalPrice" value={this.state.payment.totalPrice} hidden/></span></td>
</tr>
</table>
<button type="submit" form="hook-form">Betaal</button>
</form>
<Button onClick={()=>this.payOrder()} >Betaal bestelling!</Button>
</Col>
<Col sm={3}></Col>
</Row>
</div>
);
}
};
export default PayBreakfastComponent;
Example url is: https://app.biejanssen.nl/ontbijt-betaling/-MWTRAO7Lhjqc47-y6z-
Does anyone understand where the difference is or how this is possible?

If you look at browser DevTools you'll see the following error:
Uncaught SyntaxError: Unexpected token '<'
[
This error typically means a JavaScript was requested from the server and it returned HTML instead.
If you look at the source of https://app.biejanssen.nl/ontbijt-betaling/-MWTRAO7Lhjqc47-y6z- You'll find the script tag loading the main chunk from a relative path:
<script src="./static/js/main.cc963dc1.chunk.js"></script>
Resulting in loading the JavaScript file from:
https://app.biejanssen.nl/ontbijt-betaling/static/js/main.cc963dc1.chunk.js
The file file doesn't exist at that path and if you look at the resources loaded for https://app.biejanssen.nl/dashboard you'll find the JavaScript file actually exists at:
https://app.biejanssen.nl/static/js/main.cc963dc1.chunk.js
You need to update the the app to always load JavaScript and other resources from the root of the domain. Something like the following without the . at the start of the path:
<script src="/static/js/main.cc963dc1.chunk.js"></script>

Related

Prints in console, but not in on page?

Can anyone spot the issue here?
import React from 'react'
export default function CoinTable(props){
props.data.map(row=> {
console.log(row.first_name)
})
return (
<table>
<thead>
<tr>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
<th>Subscription</th>
</tr>
</thead>
<tbody>
{
props.data.map(row => {
<tr>
<td>{row.first_name} {row.last_name}</td>
<td>{row.phone}</td>
<td>{row.email}</td>
</tr>
})
}
</tbody>
</table>
)
}
For some reason the code appears on console but not on the screen. I am also printing from a JSON file if that helps.
You don't return the DOM in map.
props.data.map(row => {
return (
<tr>
<td>{row.first_name} {row.last_name}</td>
<td>{row.phone}</td>
<td>{row.email}</td>
</tr>
)
})
Or precisely:
props.data.map(row => (
<tr>
<td>{row.first_name} {row.last_name}</td>
<td>{row.phone}</td>
<td>{row.email}</td>
</tr>
))

Dynamic <table> not rendering data

I'm trying to create a dynamic table that renders data inserted based on a format of
{headers: ["header1", "header2"], rows: [["data1", "data2"], ["moredata", "wowoso muchdata"]]}
Rows is just an array of arrays and each array is a row in the table.
I pass this data into a React component which renders the table. The code is the following:
export default class StandardTable extends React.Component<Props, State>{
constructor(props){
super(props);
this.state = {
tableData: this.props.data
}
}
render(){
return(
<div>
<table id="StandardTable">
<tbody>
{this.state.tableData.headers.map(function(header){
<th>{header}</th>
})}
</tbody>
<tbody>
{this.state.tableData.rows.map(function(row){
<tr>
{row.map(function(rowItem){
<td>{rowItem}</td>
})}
</tr>
})}
</tbody>
</table>
<style jsx>
{`
#StandardTable{
border: 1px solid black;
}`}
</style>
</div>
);
}
}
I am able to console log the data object and all the data is there. It's also iterating through the data in the map functions as I can check in console, but unfortunately the table shows up blank in practice.
can you try this, no need to return, you can use arrow function
<table id="StandardTable">
<tbody>
{this.state.tableData.headers.map((header) => (
<th>{header}</th>
))}
</tbody>
<tbody>
{this.state.tableData.rows.map((row)=>(
<tr>
{row.map((rowItem)=>(
<td>{rowItem}</td>
))}
</tr>
))}
</tbody>
</table>
Hope it will work.
It's because you forgot the return. Just do this in your map functions:
{this.state.tableData.headers.map(function(header){
return <th>{header}</th>
})}
There is no return in map
this.state.tableData.rows.map(function(row){
return( <tr>
{row.map(function(rowItem){
return <td>{rowItem}</td>
})}
</tr>)
})

How to retrieve dynamic box values (true or false if checked or not) - Angular 6

I use Angular 6, I get data from a JSON file and I display it in a table. I would like to be able to check the checkboxes in order to be able to carry out POST processing later for checkbox checked (so true).
The problem is that I get dynamic values so I have to be able to retrieve the value of a checkbox (true or false) even if the JSON file changes (adding data).
I can not get the value of checkbox (true or false) dynamically...
Can you help me please.
demande-ouverture-compte.component.html :
<h2>Demandes d'ouverture de compte</h2>
<hr>
<form #form = "ngForm" (ngSubmit) = "getVerificationCheckboxValidation(form)" [formGroup]="profileForm">
<table class="table table-striped table-dark">
<thead>
<tr>
<th scope="col">Nom</th>
<th scope="col">N° demande</th>
<th scope="col">date</th>
<th scope="col">Validation</th>
</tr>
</thead>
<tbody *ngFor="let demande of demandes; let i = index">
<tr>
<th scope="row">{{ demande.nom }}</th>
<td>{{ demande.id_demande }}</td>
<td>{{ demande.date }}</td>
<td>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" name="test" id="customCheck{{ i }}" [checked]="demande.checked">
<label class="custom-control-label" for="customCheck{{ i }}">Valider la demande d'ouverture</label>
</div>
</td>
</tr>
</tbody>
</table>
<table>
<tr *ngFor="let demande of demandes; let j = index">
<td>
<input type="checkbox" [checked]="demande.checked" formControlName="hello" id="{{demande.roleID}}" />
</td>
<td>
</td>
<td>Voici demandes{{ j }}</td>
</tr>
</table>
<button class="col-2 offset-10 addAccount">Valider</button>
</form>
<!-- Remplacer le bouton valider par cette image -->
<!--<img src="../../assets/img/addAccount.svg" alt="" class="col-4 offset-7 addAccount">-->
demande-ouverture-compte.component.ts :
import { Component, OnInit } from '#angular/core';
import { DemandeOuvertureCompteService } from '../demande-ouverture-compte.service';
import { FormGroup, FormControl, NgForm } from '#angular/forms';
#Component({
selector: 'app-demande-ouverture-de-compte',
templateUrl: './demande-ouverture-de-compte.component.html',
styleUrls: ['./demande-ouverture-de-compte.component.scss']
})
export class DemandeOuvertureDeCompteComponent implements OnInit {
demandes: Object;
profileForm = new FormGroup({
hello: new FormControl('')
});
playerName: string;
constructor(private demandeOuvertureCompte: DemandeOuvertureCompteService) { }
ngOnInit() {
this.demandeOuvertureCompte.getDemandesOuvertureCompte().subscribe(
demandeOuvertureCompte => this.demandes = demandeOuvertureCompte
);
}
getVerificationCheckboxValidation(form: NgForm) {
console.log(form.value.test);
console.log(this.profileForm.value);
console.log("test");
console.log(this.playerName);
return this.playerName;
}
}
You can look for the valueChanges on FormGroup. Something like
ngOnInit() {
this.profileForm.valueChanges.subscribe(
value => console.log(value);
)

Data not displayed on Grid in angular 4

I want to populate my grid with the data which i am receiving from API
below is my API response which i am getting
[
{
"intUserId": 1109,
"vcrFirstName": "sdvlbs",
"vcrLastName": "dsbvsdfn",
"vcrLoginName": "!##DBASDI?\"|}",
"vcrPassword": "eclerx#123",
"vcrStatus": "InActive",
"vcrIsClient": "eClerx",
"vcrEmail": "sdvlbs.dsbvsdfn#eClerx.com",
"vcrRole": "Analyst,Auditor,Team Lead,Manager",
"Agreements_Selected": "ISDA,CSA,Repo,SLA,PBA"
}
]
But at the time of passing this data to HTML by grid is still blank
Below is my .ts code
arrBirds:Array<string> = [];
userdata(){
this.http.get(this.url).subscribe((res)=>{
this.arrBirds = Array.of(res.json()) ;
console.log(this.arrBirds)
});
}
Below is my HTML
<table cellpadding="0" width="100%" cellspacing="0" border="0" class="search_grid_view table-striped">
<thead>
<tr>
<th style="min-width: 100px;">Login Name</th>
<th>First Name</th>
<th>Last Name</th>
<th>Role</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let char of arrBirds">
<td >
{{char.vcrPassword}}
</td>
<td >
{{char.vcrStatus}}
</td>
<td >
{{char.Agreements_Selected}}
</td>
<td >
{{char.vcrEmail}}
</td>
</tr>
</tbody>
</table>
i am trying to iterate the data which i am receiving from API response
Below is my API code
public HttpResponseMessage GetCheckBoxes()
{
HttpResponseMessage response;
UserDB userDB = new UserDB();
DataSet ds = userDB.UserGridDetails();
string json = JsonConvert.SerializeObject(ds.Tables[0], Formatting.Indented);
//response = Request.CreateResponse(HttpStatusCode.OK, "[" + json + "]");
response = Request.CreateResponse(HttpStatusCode.OK, json);
return response;
}
my grid doesn't populate with the data.
i am struggling since last 5 days.
I think html file is not in sync with http response
<tr *ngFor="let char of arrBirds">
<td > {{char?.vcrPassword}}</td>
<td > {{char?.vcrStatus}} </td>
<td > {{char?.Agreements_Selected}}</td>
<td > {{char?.vcrEmail}} </td>
</tr>
Change this in tr,it will work.
If it still don't work then import ChangeDetectorRef from angular/core
inject it in constructor and use detectchanges method in ChangeDetectorRef
import { Component, Input, ChangeDetectionStrategy, ChangeDetectorRef } from '#angular/core';
constructor(private ref: ChangeDetectorRef) {}
userdata(){
this.http.get(this.url).subscribe((res)=>{
this.arrBirds = Array.of(res.json()) ;
this.ref.detectChanges();
console.log(this.arrBirds)
});
}
Hope It helps.
By parsing the JSON data it is working now.
userdata(){
this.http.get(this.url).subscribe((res)=>{
this.arrBirds = JSON.parse(res.json()) as Application[];
console.log(this.arrBirds)
});
}

AngularJS :- Calling a function query

Building a Shpping Cart using AngularJS .
I had code the code from a user on JSFiddle.
JS:-
function CartForm($scope) {
$scope.invoice = {
items: [{
qty: 10,
description: 'item',
cost: 9.95}]
};
$scope.addItem = function() {
$scope.invoice.items.push({
qty: 1,
description: '',
cost: 0
});
},
$scope.removeItem = function(index) {
$scope.invoice.items.splice(index, 1);
},
$scope.total = function() {
var total = 0;
angular.forEach($scope.invoice.items, function(item) {
total += item.qty * item.cost;
})
return total;
}
}
HTML
<h2>Shopping Card Example</h2>
<div ng:controller="CartForm">
<table class="table">
<tr>
<th>Description</th>
<th>Qty</th>
<th>Cost</th>
<th>Total</th>
<th></th>
</tr>
<tr ng:repeat="item in invoice.items">
<td><input type="text" ng:model="item.description"class="input-small" readonly="readonly"></td>
<td><input type="number" ng:model="item.qty" ng:required class="input-mini"> </td>
<td><input type="number" ng:model="item.cost" ng:required class="input-mini" readonly="readonly"></td>
<td>{{item.qty * item.cost | currency}}</td>
<td>
[<a href ng:click="removeItem($index)">X</a>]
</td>
</tr>
<tr>
<td><a href ng:click="addItem()" class="btn btn-small">add item</a></td>
<td></td>
<td>Total:</td>
<td>{{total() | currency}}</td>
</tr>
</table>
</div>
I want to have the add item outside the table . How do I access the addItem function outside the outside the above snippet of HTML code.
JS Fiddle http://jsfiddle.net/slav123/75m7e/
Your problem is related to scope visibility: you define your cart login in the CartForm scope and you want to access that logic from outside that scope.
There are several ways of doing that:
You could always do it the nasty way: pin any global funcionalities to the $rootScope to make them visible throughout the whole app:
function CartForm($scope, $rootScope) {
// ...
$rootScope.addItem = $scope.addItem;
}
Or you could try a cleaner way: you should pack your cart functionalities into a shared service that you can inject wherever you need it:
app.factory('CartService', function() {
// some cart logic here
// return your cart api
return {
addItem: function() {/*...*/}
}
});
After you defined yor cart logic as a factory, you can use it anywhere you want by simply injecting it as a dependency:
app.controller('MyPageCtrl', function($scope, CartService) {
$scope.cart = CartService;
});
and use the functionality into the view:
<a href ng:click="cart.addItem()" class="btn btn-small">add item</a>