I am using primeng ConfirmationService to display confirm dialog. After the first dialog is confirmed, i want to display another dialog based on a condition. But it is not working. Here is my code. Can anyone help me how to solve this?
this.confirmDialog.confirm({
header: 'Begin',
message: 'Are you sure you would like to start?',
acceptLabel: 'Yes',
rejectLabel: 'No',
accept: () => {
if(this.currentUserId !== workflow.assignedToId) {
this.confirmDialog.confirm({
header: 'Reassign',
message: 'reassign it to yourself?',
acceptLabel: 'Yes',
rejectLabel: 'No',
accept: () => {
console.log('accept 2 diffeent user');
},
reject: () => {
console.log('reject 2 diffeent user');
}
})
} else {
console.log('accept 1 same user');
}
},
reject: () => {
console.log('reject 1 same user');
}
})
you need to create 2 confirmDialog with different key value:
<p-confirmDialog [style]="{ width: '50vw' }" [baseZIndex]="10000" key="confirm1"></p-confirmDialog>
<p-confirmDialog [style]="{ width: '50vw' }" [baseZIndex]="10000" key="confirm2" ></p-confirmDialog>
and you need to add the key to the confirmationService function like this:
confirm1() {
this.confirmationService.confirm({
message: 'Are you sure that you want to proceed?',
header: 'Confirmation',
icon: 'pi pi-exclamation-triangle',
key: 'confirm1',
accept: () => {
this.confirm2();
this.msgs = [
{
severity: 'info',
summary: 'Confirmed',
detail: 'You have accepted',
},
];
},
reject: () => {
this.msgs = [
{
severity: 'info',
summary: 'Rejected',
detail: 'You have rejected',
},
];
},
});
}
confirm2() {
this.confirmationService.confirm({
message: 'Do you want to delete this record?',
header: 'Delete Confirmation',
icon: 'pi pi-info-circle',
key: 'confirm2',
accept: () => {
this.msgs = [
{ severity: 'info', summary: 'Confirmed', detail: 'Record deleted' },
];
},
reject: () => {
this.msgs = [
{
severity: 'info',
summary: 'Rejected',
detail: 'You have rejected',
},
];
},
});
}
you can see an example on Stackblitz
https://stackblitz.com/edit/primeng-confirmdialog-demo-v1x93e?file=src/app/app.component.ts
Related
I've created a React table, and I have a data in Elasticsearch. I have successfully fetched data from Elasticsearch using API(fetch) call; this data is being displayed in the console but not in screen. How to solve this problem?
this code will fetch data from Elasticsearch, then display it on React Table.
import './App.css';
import Table from './pages/Table';
import { useEffect, useState } from 'react';
function App() {
const [dataTable, setDataTable] = useState([]);
// this is our JOSN data to be displayed in the console
var myHeaders = new Headers();
myHeaders.append("Authorization", "Basic xxcxxxxxxxxx==");
myHeaders.append("Content-Type", "application/json");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
// this is fetching data from Elastic and working successfully
useEffect(() => {
fetch("https://192.168.1.3:9200/myapp/_doc/1", requestOptions)
.then(response => response.json())
.then(result => setDataTable(result.data)) // the error comes here
.catch(error => console.log('error', error));
}, []);
console.log(dataTable);
const column = [
{ heading: 'Id', value: '_index' },
{ heading: 'Index', value: '_index' },
{ heading: 'Score', value: '_score' },
{ heading: 'Timestamp', value: '#timestamp' },
{ heading: 'Version', value: '#version' },
{ heading: 'Ephemeral Id', value: 'agent.ephemeral_id' },
{ heading: 'Agent Id', value: 'agent.id' },
{ heading: 'Agent name', value: 'agent.name' },
{ heading: 'Agent type', value: 'agent.type' },
{ heading: 'Agent Version', value: 'agent.version' },
{ heading: 'esc version', value: 'esc.version' },
{ heading: 'event original', value: 'event.original' },
{ heading: 'host architecture', value: 'host.architecture' },
{ heading: 'host hostname', value: 'host.hostname' },
{ heading: 'host id', value: 'host.id' },
{ heading: 'host ip', value: 'host.ip' },
{ heading: 'host mac', value: 'host.mac' },
{ heading: 'host name', value: 'host.name' },
{ heading: 'host os build', value: 'host.os.build' },
{ heading: 'host os family', value: 'host.os.family' },
{ heading: 'host os kernel', value: 'host.os.kernel' },
{ heading: 'host os name', value: 'host.os.name' },
{ heading: 'host os platform', value: 'host.os.platform' },
{ heading: 'host os type', value: 'host.os.type' },
{ heading: 'host os version', value: 'host.os.version' },
{ heading: 'input type', value: 'input.type' },
{ heading: 'log file path', value: 'log.file.path' },
{ heading: 'log offset', value: 'log.offset' },
{ heading: 'message', value: 'message' },
{ heading: 'tags', value: 'tags' },
]
// console.log(column)
return (
<div className="App" >
<h1>eSafe Table</h1>
<Table data={dataTable} column={column} />
</div>
);
}
export default App;
I'm building an application based on user survey in React JS.
All the questions are coming from API as JSON response
const data = {
preQuestions: {
landingPage: {
heading: 'This is the ladning page',
buttons: {
yesButton: {
text: 'yes',
action: '1A',
},
noButton: {
text: 'No',
action: '1B',
},
},
},
'1A': {
heading: 'This is the 1A Component',
buttons: {
yesButton: {
text: 'yes',
action: '1C',
},
noButton: {
text: 'No',
action: '1D',
},
},
},
'1B': {
heading: 'This is the 1B Component',
buttons: {
yesButton: {
text: 'yes',
action: '1C',
},
noButton: {
text: 'No',
action: '1D',
},
},
},
'1C': {
heading: 'This is the 1C Component',
buttons: {
yesButton: {
text: 'yes',
action: '1A',
},
noButton: {
text: 'No',
action: '1B',
},
},
},
'1D': {
heading: 'This is the 1D Component',
buttons: {
yesButton: {
text: 'yes',
action: '1B',
},
noButton: {
text: 'No',
action: '1C',
},
},
},
},
};
I wanted to display only 1st question by default and based on the user response I need to load the second question on same page, where use can able to see the previous question .
Basically I wanted to stack all the questions one below the other based on user actions.
But current with my logic, When user selects the next question, prev question getting disappeared.
Below is my code,
const [active, setActive] = React.useState<any>(
data.preQuestions['landingPage']
);
const content = data.preQuestions;
const loadNextCompnent = (actionId) => {
setActive(actionId);
};
const renderQustionComponent = () => {
Previous question
return (
<div>
<h1>{active?.heading}</h1>
<button
onClick={() =>
loadNextCompnent(content[active?.buttons?.yesButton?.action])
}
>
{active.buttons.yesButton.text}{' '}
</button>
<button
onClick={() =>
loadNextCompnent(content[active?.buttons?.noButton?.action])
}
>
{active.buttons.noButton.text}{' '}
</button>
</div>
);
};
return <div>{renderQustionComponent()}</div>;
How Can I stack all the questions one below the other ? Please help.
Working Stackblitz link https://stackblitz.com/edit/react-ts-z8clfj
I want to validate a discord embed before sending it.
Which means, I want to know if an embed has nothing wrong with it before actually sending it on a channel.
var embed = {
title: 'some title',
description: 'some description',
color: 'foo bar'
}
// embed.color is not a valid color, so it will trigger an error when I send it.
// Here I want some way to know that there's something wrong with the embed object.
message.channel.send({embed});
I have made a function to validate embeds. However, it's incomplete and may have false positives or false negatives, but it should meet your needs.
function validURL(url) {
try {
new URL(url);
} catch (err) {
return false;
}
return true;
}
function validEmbed(embed) {
return Object.entries({
title: (title) => typeof title === 'string',
description: (description) => typeof description === 'string',
url: (url) => validURL(url),
timestamp: (timestamp) => (new Date(timestamp)).getTime() > 0,
color: (color) => typeof color === 'number',
fields: (fields) => fields.every(field => typeof field.name === 'string' && typeof field.value === 'string' && typeof field.inline === 'boolean'),
thumbnail: (thumbnail) => validURL(thumbnail.url),
image: (image) => validURL(image.url),
author: (author) => typeof author.name === 'string' && validURL(author.url) && validURL(author.icon_url),
footer: (footer) => typeof footer.text === 'string' && validURL(footer.icon_url)
}).every(field => {
if (!(field[0] in embed)) return true;
return embed[field[0]] && field[1](embed[field[0]]);
});
}
Here is an exaple snippet:
function validURL(e){try{new URL(e)}catch(e){return!1}return!0}function validEmbed(e){return Object.entries({title:e=>"string"==typeof e,description:e=>"string"==typeof e,url:e=>validURL(e),timestamp:e=>new Date(e).getTime()>0,color:e=>"number"==typeof e,fields:e=>e.every(e=>"string"==typeof e.name&&"string"==typeof e.value&&"boolean"==typeof e.inline),thumbnail:e=>validURL(e.url),image:e=>validURL(e.url),author:e=>"string"==typeof e.name&&validURL(e.url)&&validURL(e.icon_url),footer:e=>"string"==typeof e.text&&validURL(e.icon_url)}).every(t=>!(t[0]in e)||e[t[0]]&&t[1](e[t[0]]))}
/* returns true */
console.log(validEmbed({
title: 'The title'
}));
/* returns true */
console.log(validEmbed({
title: 'The title',
description: 'Sample Description.',
url: 'https://i.imgur.com/ttHwmCl.jpg',
timestamp: '2020-07-30T14:44:05.876Z',
color: 3447003,
fields: [{
name: 'name',
value: 'value',
inline: false
},
{
name: 'name2',
value: 'value2',
inline: true
}
],
thumbnail: {
url: 'attachment://stackoverflow2.jpg'
},
image: {
url: 'attachment://stackoverflow.jpg'
},
author: {
name: 'Daemon Beast',
url: 'https://i.imgur.com/P4L260P.jpg',
icon_url: 'https://i.imgur.com/P4L260P.jpg'
},
footer: {
text: 'footer text',
icon_url: 'https://i.imgur.com/ttHwmCl.jpg'
}
}));
/* returns false */
console.log(validEmbed({
author: 4567876567
}));
I have a button that logs an event. When the button is clicked it automatically picks the chosen date from a calendar. after this the user would have to register two boolean attributes. I don't know how to do this efficiently. Can someone help me?
async cadastrarPresenca() {
let ida: boolean;
let volta: boolean;
const alert = await this.alertController.create({
header: 'Confirmar ida e/ou volta',
inputs: [
{
name: 'Ida',
type: 'checkbox',
label: 'Ida',
value: ida,
},
{
name: 'Volta',
type: 'checkbox',
label: 'Volta',
value: volta
}],
buttons: [
{
text: 'Cancel',
role: 'cancel',
cssClass: 'secondary',
handler: () => {
console.log('Confirm Cancel');
}
}, {
text: 'Ok',
handler: () => {
let start = this.dataSelecionada;
let end = this.dataSelecionada;
end.setMinutes(end.getMinutes() + 60);
let presenca = {
title: 'Event #' + start.getMinutes(),
startTime: start,
endTime: end,
allDay: false,
ida: ida,
volta: volta
};
this.firestore.collection('aluno').doc(this.authService.getUsuario().uid).collection('presenca').add(presenca);
}
}
]
});
await alert.present();
You just need to update your ok handler so that the data is passed in and then you can use it:
async cadastrarPresenca() {
let ida: boolean;
let volta: boolean;
const alert = await this.alertController.create({
header: 'Confirmar ida e/ou volta',
inputs: [
{
name: 'Ida',
type: 'checkbox',
label: 'Ida',
value: ida,
},
{
name: 'Volta',
type: 'checkbox',
label: 'Volta',
value: volta
}],
buttons: [
{
text: 'Cancel',
role: 'cancel',
cssClass: 'secondary',
handler: () => {
console.log('Confirm Cancel');
}
}, {
text: 'Ok',
// NEW CODE HERE
handler: (inputData) => {
console.log(inputData);
console.log(inputData["Volta"].checked);
// END OF NEW CODE HERE
let start = this.dataSelecionada;
let end = this.dataSelecionada;
end.setMinutes(end.getMinutes() + 60);
let presenca = {
title: 'Event #' + start.getMinutes(),
startTime: start,
endTime: end,
allDay: false,
ida: ida,
volta: volta
};
this.firestore.collection('aluno').doc(this.authService.getUsuario().uid).collection('presenca').add(presenca);
}
}
]
});
await alert.present();
So the new code is all that I've changed from your snippet:
// NEW CODE HERE
handler: (inputData) => {
console.log(inputData);
console.log(inputData["Volta"].checked);
// END OF NEW CODE HERE
You can look at the code that Ionic is built on for reference to see what options should be available, or just check out the first console.log I added.
Here I'm trying to get the current path, but also have problem and says that Cannot read property 'replace' of undefined. Who could help me to resolve this problem ?
handleClick= (event: SyntheticMouseEvent<HTMLButtonElement>) => {
const { workflowPath: _workflowPath } = this.props;
let workflowPath = _workflowPath;
Object.keys(this.props.row._original).forEach((key) => {
workflowPath = workflowPath.replace(`{${key}`, this.props.row._original[key]);
});
this.props.startFlow(workflowPath);
this.setState({ loading: true });
};
Also this handleClick is in component which is called Cell.
Header: 'Status',
accessor: 'status',
label: 'Change status',
type: 'workflow',
workflowPath: 'process/task/change_status',
icon: <Launch />,
items: [
{
label: 'New',
},
{
label: 'In progress',
},
{
label: 'Rejected',
},
{
label: 'Complete',
},
],
Cell: WorkflowColumn,
I believe it should be:
workflowPath && workflowPath.length &&
Object.keys(this.props.row._original).forEach((key) => {
...
This will check that workflowPath actually has something in it. If it's null this leads to the error you have been experiencing.