From 90686063855f393b9738de39937b2b75bb87cb2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20M=C3=A4mecke?= Date: Mon, 4 Mar 2024 17:53:54 +0100 Subject: [PATCH] Improve docs --- README.md | 138 +-------------- docs/README.md | 4 + docs/porting-embed.md | 391 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 399 insertions(+), 134 deletions(-) create mode 100644 docs/README.md create mode 100644 docs/porting-embed.md diff --git a/README.md b/README.md index 1bfe53b..0a7fd2b 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ npm install @gigs/gigs-embeds-js ## Getting started -To use Gigs Embeds, you need +To use Gigs Embeds, you need: 1. A Gigs project 2. A Gigs API Key @@ -22,9 +22,7 @@ To use Gigs Embeds, you need > [!INFO] > Your not yet a Gigs customer? [Get in touch](https://gigs.com/contact) to discuss the next steps! -## Usage - -### How it works +## How it works Using a Gigs Embed needs 2 parts: @@ -35,137 +33,9 @@ When using Connect Sessions with Gigs Embeds, you do not redirect to the session Additionally, you can subscribe to [Webhooks](https://developers.gigs.com/docs/api/441a2e9e7811d-events-and-webhooks) to get a verified outcome of a user's interaction, like when they completed a number porting. The Embeds are also returning the outcome of a user's interaction, but you should use Webhooks for mission-critical processes like updating a record in your database based on the outcome. -### Porting Embed - -The Porting Embed allows a user to complete a number porting inside your app. - -```js -// index.js - -// You can pass the Connect Session to the browser however you want. -const session = await fetchSessionForCurrentUser() - -// Initialize the embed with the session. -const embed = await PortingEmbed(session, { - project: 'your-project-id', - options: { - className: { - // The embed offers extensive customization options. See more details in - // the reference below. - input: () => 'custom-class-names', - }, - }, -}) - -// After the initization, you can hide any loading states... -document.getElementById('loading').remove() - -// ...and mount the embed. -embed.mount('#embedMount') // you can use a string selector or an element reference. - -// You can listen to events to reflect changes in the embed in your own UI. -embed.on('submitStatus', ({ status }) => { - if (status === 'loading') { - document.querySelector('#submit').disabled = true - document.querySelector('#submit').innerText = 'Loading...' - } - if (status === 'success') { - document.querySelector('#submit').disabled = false - document.querySelector('#submit').innerText = 'Save' - } -}) - -// Once the porting is completed, you can redirect the user to the next page. -embed.on('completed', ({ porting }) => { - location.href = 'https://your-site.com/porting-completed' -}) -``` - -```html - - -
Loading...
- - -
- - - -``` - -## Reference - -### Porting Embed - -```js -const embed = await PortingEmbed(connectSession, { - project, - options, -}) -``` - -`connectSession` -The complete Connect Session object which you created on your server and passed to the browser. Is required. - -`project` -The ID of your Gigs Project. - -`options` -Additional options to customize the embed. - -#### Options - -All options are optional. - -`formId: string` -Will be used inside the embed as `
`. Defaults to `gigsPortingEmbedForm`. - -`className.form({ name, dirty, valid, submitting, touched }) => string` -Generate custom class names for the `` element of the embed. - -`className.field({ name, dirty, valid, touched }) => string` -Generate custom class names for the `
` element of the embed which wraps a form field, consisting of an input, label and error message. - -`className.input({ name, dirty, valid, touched }) => string` -Generate custom class names for the `` element of the embed. - -`className.label({ name, dirty, valid, touched }) => string` -Generate custom class names for the `