Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Website Forms #8

Merged
merged 123 commits into from
Jun 30, 2024
Merged

Website Forms #8

merged 123 commits into from
Jun 30, 2024

Conversation

rockwellll
Copy link
Collaborator

This PR adds a dedicated module/namespace for handling forms. Forms, as described in this guide can be created through the dashboard, then Hellotext.js would be responsible for creating, authenticating and validating the values users submit.

Reorganization

This PR performer a major overhaul over the structure of the library. Almost all top-level files have been moved into a dedicated folder, such as core, models, controllers, builders.

Global Config object

This PR introduced a global config class that's accessible by every other class in the package. This is useful for holding package-wide information in a single register. For example, it holds the API root url,

static apiRoot = 'https://api.hellotext.com/v1'

And dedicated API files use that root to generate an endpoint,

static get endpoint() {
return Configuration.endpoint('public/businesses')
}
static async get(id) {
return fetch(`${this.endpoint}/${id}`, {
method: 'GET',
headers: {
Authorization: `Bearer ${id}`,
Accept: 'application.json',
'Content-Type': 'application/json',
},
})
}

APIs

This PR expands over the set of APIs the package interacts with, and thus a dedicated folder api has been introduced to hold endpoints for the various objects this package uses. See the available ones in https://github.com/hellotext/hellotext.js/tree/forms/src/api.

Forms

This PR adds a new module, namely Forms which is exposed under Hellotext.forms, which returns an instance of FormCollection. Hellotext.js, once initialized attached a load event listener to the window, once loaded it looks for elements in the document via data-hello-form identifier and fetches their public information via public/forms endpoint.

Collected forms can be mounted manually to keep the developer in control, a form can be mounted by calling the mount method on the object, such as

Hellotext.forms.getByIndex(1).mount()

Events

Underneath, this PR overhauls the event management code, on the outside, this PR introduces 2 new events, namely forms:collected and form:completed.

In addition, we've introduced prettier to style the codebase.

@rockwellll rockwellll merged commit d4b9894 into main Jun 30, 2024
2 checks passed
@rockwellll rockwellll deleted the forms branch June 30, 2024 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant