Deprecated as of Novemeber 2024. Please use New Library(B_Block v2.0)

Dialog Box Component

Dialog Box component can be used to render a dialog box.

<Dialog /> uses an additional package called gbs-fwk-core. This package is already shipped with the gbs-fwk-buildingblock so just import it as well.

Add <Dialog /> Component to App.tsx[or wherever you prefer to add].

App.tsx
import { Dialog } from 'gbs-fwk-buildingblock';
 
function App() {
  return (
    <div className="App">
      <Dialog />
    </div>
  );
}
 
export default App;

Props

PropertyTypeDescription
keystringThe unique identifier for the dialog box
typestringThe type of the dialog box
titlestringThe title of the dialog box
contentstringThe content of the dialog box
positionobjectThe position of the dialog box on the screen
okButtonobjectThe configuration for the "OK" button
cancelButtonobjectThe configuration for the "Cancel" button
widthstringThe width of the dialog box

Types of Dialogs

There are two types of dialog types.

  1. type: "alert" : Produces a alert dialog with one button(There is no need of cancelButton Props here.)
  2. type: "confirm: Produces a dialog with a multiple option.

Usage

Here's an example of how to use the Dialog Box component:

Functional Component
App.tsx
import { messageService } from 'gbs-fwk-core';
 
export default function DeleteAction() {
  let subscription: any;
 
  const handleOnClick = () => {
    if (subscription) {
      subscription.unsubscribe();
    }
    subscription = messageService.getMessage().subscribe((message: any) => {
      if (message.key === '') {
        console.log(message.status);
      } else if (message.key === 'item_delete_callback') {
        console.log(message.status);
      }
    });
 
    messageService.sendMessage({
      key: 'dialog_alert',
      type: 'confirm', // *You can choose either "confirm" or "alert" here!
      title: 'Are you sure?',
      keyData: keyData, // for entity values(Optional)
      content: 'This is how a error look like!',
      position: { X: 'center', Y: 'center' },
      okButton: { text: "I'm in", icon: 'e-icons e-check' },
      cancelButton: { text: "I don't think so!", icon: 'e-icons e-close' },
      callbackUrl: 'item_delete_callback',
      width: '300px',
    });
  };
 
  return (
    <div>
      <div>Delete Action</div>
      <button onClick={handleOnClick}>Delete This!</button>
    </div>
  );
}
Class Component
App.tsx
import React from 'react';
import { messageService } from 'gbs-fwk-core';
 
class DeleteAction extends React.Component {
  subscription: any;
 
  handleOnClick = () => {
    if (subscription) {
      subscription.unsubscribe();
    }
    subscription = messageService.getMessage().subscribe((message: any) => {
      if (message.key === '') {
        console.log(message.status);
      } else if (message.key === 'item_delete_callback') {
        console.log(message.status);
      }
    });
 
    messageService.sendMessage({
      key: 'dialog_alert',
      type: 'alert', // *You can choose either "confirm" or "alert" here!
      title: 'Are you sure?',
      content: 'This is how a error look like!',
      position: { X: 'center', Y: 'center' },
      okButton: { text: "I'm in", icon: 'e-icons e-check' },
      cancelButton: { text: "I don't think so!", icon: 'e-icons e-close' },
      callbackUrl: 'item_delete_callback',
      width: '300px',
    });
  };
 
  render() {
    return (
      <div>
        <div>Delete Action</div>
        <button onClick={this.handleOnClick}>Delete This!</button>
      </div>
    );
  }
}
 
export default DeleteAction;