Skip to content

Commit

Permalink
feat(client): add getAddressFormFields query
Browse files Browse the repository at this point in the history
  • Loading branch information
yurytut1993 committed Mar 21, 2024
1 parent b38785a commit da1d0d0
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions apps/core/client/queries/get-address-form-fields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { cache } from 'react';

import { client } from '..';
import { FormFieldFiltersInput, FormFieldSortInput } from '../generated/graphql';
import { graphql } from '../graphql';
import { revalidate } from '../revalidate-target';

interface AddressFormFields {
filters?: FormFieldFiltersInput;
sortBy?: FormFieldSortInput;
}

const GET_ADDRESS_FORM_FIELDS = graphql(`
query getAddressFormFields($filters: FormFieldFiltersInput, $sortBy: FormFieldSortInput) {
site {
settings {
formFields {
shippingAddress(filters: $filters, sortBy: $sortBy) {
entityId
label
sortOrder
isBuiltIn
isRequired
__typename
... on CheckboxesFormField {
options {
entityId
label
}
}
... on DateFormField {
defaultDate
minDate
maxDate
}
... on MultilineTextFormField {
defaultText
rows
}
... on NumberFormField {
defaultNumber
maxLength
minNumber
maxNumber
}
... on PasswordFormField {
defaultText
maxLength
}
... on PicklistFormField {
choosePrefix
options {
entityId
label
}
}
... on RadioButtonsFormField {
options {
entityId
label
}
}
... on TextFormField {
defaultText
maxLength
}
}
}
}
}
}
`);

export const getAddressFormFields = cache(async ({ filters, sortBy }: AddressFormFields) => {
const response = await client.fetch({
document: GET_ADDRESS_FORM_FIELDS,
variables: { filters, sortBy },
fetchOptions: { next: { revalidate } },
});

const { settings } = response.data.site;

if (!settings) {
return null;
}

return settings.formFields.shippingAddress;
});

0 comments on commit da1d0d0

Please sign in to comment.