@wix/members 1.0.541 → 1.0.543
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/account-details-context-provider/package.json +3 -0
- package/account-home-context-provider/package.json +3 -0
- package/address-context-provider/package.json +3 -0
- package/addresses-context-provider/package.json +3 -0
- package/build/cjs/context-account-details.d.ts +246 -0
- package/build/cjs/context-account-details.js +9513 -0
- package/build/cjs/context-account-details.js.map +1 -0
- package/build/cjs/context-account-home.d.ts +54 -0
- package/build/cjs/context-account-home.js +719 -0
- package/build/cjs/context-account-home.js.map +1 -0
- package/build/cjs/context-address.d.ts +52 -0
- package/build/cjs/context-address.js +587 -0
- package/build/cjs/context-address.js.map +1 -0
- package/build/cjs/context-addresses.d.ts +104 -0
- package/build/cjs/context-addresses.js +9054 -0
- package/build/cjs/context-addresses.js.map +1 -0
- package/build/cjs/context-authentication.d.ts +633 -0
- package/build/cjs/context-authentication.js +4253 -0
- package/build/cjs/context-authentication.js.map +1 -0
- package/build/es/context-account-details.d.mts +246 -0
- package/build/es/context-account-details.mjs +9467 -0
- package/build/es/context-account-details.mjs.map +1 -0
- package/build/es/context-account-home.d.mts +54 -0
- package/build/es/context-account-home.mjs +690 -0
- package/build/es/context-account-home.mjs.map +1 -0
- package/build/es/context-address.d.mts +52 -0
- package/build/es/context-address.mjs +557 -0
- package/build/es/context-address.mjs.map +1 -0
- package/build/es/context-addresses.d.mts +104 -0
- package/build/es/context-addresses.mjs +9012 -0
- package/build/es/context-addresses.mjs.map +1 -0
- package/build/es/context-authentication.d.mts +633 -0
- package/build/es/context-authentication.mjs +4221 -0
- package/build/es/context-authentication.mjs.map +1 -0
- package/build/internal/cjs/context-account-details.d.ts +246 -0
- package/build/internal/cjs/context-account-home.d.ts +54 -0
- package/build/internal/cjs/context-address.d.ts +52 -0
- package/build/internal/cjs/context-addresses.d.ts +104 -0
- package/build/internal/cjs/context-authentication.d.ts +633 -0
- package/build/internal/es/context-account-details.d.mts +246 -0
- package/build/internal/es/context-account-home.d.mts +54 -0
- package/build/internal/es/context-address.d.mts +52 -0
- package/build/internal/es/context-addresses.d.mts +104 -0
- package/build/internal/es/context-authentication.d.mts +633 -0
- package/context/account-details/package.json +3 -0
- package/context/account-home/package.json +3 -0
- package/context/address/package.json +3 -0
- package/context/addresses/package.json +3 -0
- package/context/authentication/package.json +3 -0
- package/context-runtime/context-account-details/runtime.d.ts +246 -0
- package/context-runtime/context-account-details/runtime.js +14 -0
- package/context-runtime/context-account-home/runtime.d.ts +54 -0
- package/context-runtime/context-account-home/runtime.js +2 -0
- package/context-runtime/context-address/runtime.d.ts +52 -0
- package/context-runtime/context-address/runtime.js +2 -0
- package/context-runtime/context-addresses/runtime.d.ts +104 -0
- package/context-runtime/context-addresses/runtime.js +14 -0
- package/context-runtime/context-authentication/runtime.d.ts +633 -0
- package/context-runtime/context-authentication/runtime.js +6 -0
- package/package.json +86 -13
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { FC, PropsWithChildren } from 'react';
|
|
3
|
+
|
|
4
|
+
//#region ../../node_modules/type-fest/source/observable-like.d.ts
|
|
5
|
+
declare global {
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
7
|
+
interface SymbolConstructor {
|
|
8
|
+
readonly observable: symbol;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
@remarks
|
|
13
|
+
The TC39 observable proposal defines a `closed` property, but some implementations (such as xstream) do not as of 10/08/2021.
|
|
14
|
+
As well, some guidance on making an `Observable` to not include `closed` property.
|
|
15
|
+
@see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L129-L130
|
|
16
|
+
@see https://github.com/staltz/xstream/blob/6c22580c1d84d69773ee4b0905df44ad464955b3/src/index.ts#L79-L85
|
|
17
|
+
@see https://github.com/benlesh/symbol-observable#making-an-object-observable
|
|
18
|
+
|
|
19
|
+
@category Observable
|
|
20
|
+
*/
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region ../../node_modules/@wix/sdk-types/internal/build/index.d.ts
|
|
23
|
+
declare global {
|
|
24
|
+
interface ContextualClient {}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates concrete types from SDK descriptors when a contextual client is
|
|
28
|
+
* available.
|
|
29
|
+
*
|
|
30
|
+
* For a REST descriptor the built (bound) API is intersected with the original
|
|
31
|
+
* descriptor, matching what `contextualizeRESTModuleV2` returns at runtime — a
|
|
32
|
+
* value callable as the bound API and still usable as a descriptor. Keeping the
|
|
33
|
+
* descriptor half lets contextual modules be passed to descriptor-constrained
|
|
34
|
+
* helpers such as `elevate` from `@wix/sdk/context` (FEDINF-14092).
|
|
35
|
+
*
|
|
36
|
+
* The `& T` is scoped to REST descriptors — the only shape codegen wraps in
|
|
37
|
+
* `MaybeContext` — so `BuildDescriptors` (used by `createClient().use`) is left
|
|
38
|
+
* unchanged and stays bound-only. The fix lives here rather than in `elevate`,
|
|
39
|
+
* which is kept strict on purpose (see #941) so it still rejects bound-only
|
|
40
|
+
* functions that are unsafe through `createRESTModule`.
|
|
41
|
+
*/
|
|
42
|
+
declare global {
|
|
43
|
+
/**
|
|
44
|
+
* A global interface to set the exposure toggle for the SDK.
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* declare global {
|
|
48
|
+
* interface SDKExposureToggle {
|
|
49
|
+
* alpha: true;
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
*/
|
|
53
|
+
interface SDKExposureToggle {}
|
|
54
|
+
}
|
|
55
|
+
declare global {
|
|
56
|
+
/**
|
|
57
|
+
* A global interface to set the type mode for the SDK.
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* declare global {
|
|
61
|
+
* interface SDKTypeMode {
|
|
62
|
+
* strict: true;
|
|
63
|
+
* }
|
|
64
|
+
* }
|
|
65
|
+
*/
|
|
66
|
+
interface SDKTypeMode {}
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region ../../node_modules/@wix/app-builder-common/dist/utils/types.d.ts
|
|
70
|
+
type ObjectValues<T> = T[keyof T];
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/extensions/account-settings/member-field-contract.d.ts
|
|
73
|
+
/**
|
|
74
|
+
* The semantic kinds a member field can take. Shared so the context provider and the field element
|
|
75
|
+
* describe one vocabulary rather than two that drift apart.
|
|
76
|
+
*/
|
|
77
|
+
declare const MEMBER_FIELD_TYPE: {
|
|
78
|
+
readonly TEXT: "TEXT";
|
|
79
|
+
readonly NUMBER: "NUMBER";
|
|
80
|
+
readonly DATE: "DATE";
|
|
81
|
+
readonly URL: "URL";
|
|
82
|
+
readonly SOCIAL: "SOCIAL";
|
|
83
|
+
readonly CHOICE: "CHOICE";
|
|
84
|
+
readonly PHONE: "PHONE";
|
|
85
|
+
};
|
|
86
|
+
type MemberFieldType = ObjectValues<typeof MEMBER_FIELD_TYPE>;
|
|
87
|
+
/** Why a member field's value cannot be saved; a field words its own message from it. */
|
|
88
|
+
declare const MEMBER_FIELD_VALIDATION_ERROR: {
|
|
89
|
+
readonly REQUIRED: "REQUIRED";
|
|
90
|
+
readonly NUMBER: "NUMBER";
|
|
91
|
+
readonly DATE: "DATE";
|
|
92
|
+
readonly URL: "URL";
|
|
93
|
+
readonly CHOICE: "CHOICE";
|
|
94
|
+
readonly PHONE: "PHONE";
|
|
95
|
+
};
|
|
96
|
+
type MemberFieldValidationError = ObjectValues<typeof MEMBER_FIELD_VALIDATION_ERROR>;
|
|
97
|
+
interface MemberFieldOption {
|
|
98
|
+
label: string;
|
|
99
|
+
value: string;
|
|
100
|
+
}
|
|
101
|
+
interface MemberFieldInputEvent {
|
|
102
|
+
target: {
|
|
103
|
+
value?: string | number | null;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/extensions/account-settings/context-providers/account-field-input.d.ts
|
|
108
|
+
interface NamedFieldBinding {
|
|
109
|
+
/** The site's configured field title; `undefined` before the member is read, `null` when the site does not collect the field. */
|
|
110
|
+
name: string | null | undefined;
|
|
111
|
+
value: string;
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/extensions/account-settings/context-providers/account-named-fields.d.ts
|
|
115
|
+
/**
|
|
116
|
+
* The platform's own field vocabulary, named as the Members SDK names each value. A `SYSTEM` or
|
|
117
|
+
* `CONTACT` field exists on every site, so each one is addressable by name. Site-specific fields are
|
|
118
|
+
* excluded from Phase 0. The contact email is absent on purpose: the API refuses a write to it.
|
|
119
|
+
*/
|
|
120
|
+
declare const NAMED_FIELD_KEYS: {
|
|
121
|
+
readonly firstName: "customfields.system.firstname";
|
|
122
|
+
readonly lastName: "customfields.system.lastname";
|
|
123
|
+
readonly phone: "customfields.system.phone";
|
|
124
|
+
readonly title: "customfields.system.title";
|
|
125
|
+
readonly birthdate: "customfields.contact.birthdate";
|
|
126
|
+
readonly company: "customfields.contact.company";
|
|
127
|
+
readonly jobTitle: "customfields.contact.position";
|
|
128
|
+
};
|
|
129
|
+
type NamedFieldName = keyof typeof NAMED_FIELD_KEYS;
|
|
130
|
+
type NamedValidationErrors = Record<NamedFieldName, MemberFieldValidationError | null>;
|
|
131
|
+
type NamedAccountFields = Record<NamedFieldName, NamedFieldBinding> & {
|
|
132
|
+
/** Every named field's fault, grouped so the binding picker lists them under one heading. */validationErrors: NamedValidationErrors;
|
|
133
|
+
};
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/extensions/account-settings/login-info/credential-restriction.d.ts
|
|
136
|
+
/** Whether a signed-in member can change their own credentials on this page, and why not. */
|
|
137
|
+
declare const CREDENTIAL_RESTRICTION: {
|
|
138
|
+
readonly NONE: "NONE";
|
|
139
|
+
readonly SITE_OWNER: "SITE_OWNER";
|
|
140
|
+
readonly SITE_COLLABORATOR: "SITE_COLLABORATOR";
|
|
141
|
+
};
|
|
142
|
+
type CredentialRestriction = ObjectValues<typeof CREDENTIAL_RESTRICTION>;
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/extensions/account-settings/login-info/credential-dialog.d.ts
|
|
145
|
+
/** The credential dialog that is open; at most one is. */
|
|
146
|
+
declare const CREDENTIAL_DIALOG: {
|
|
147
|
+
readonly LOGIN_EMAIL: "LOGIN_EMAIL";
|
|
148
|
+
readonly PASSWORD: "PASSWORD";
|
|
149
|
+
};
|
|
150
|
+
type CredentialDialog = ObjectValues<typeof CREDENTIAL_DIALOG>;
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/extensions/account-settings/login-info/credential-error.d.ts
|
|
153
|
+
/** Why the last credential write failed. */
|
|
154
|
+
declare const CREDENTIAL_ERROR: {
|
|
155
|
+
readonly INCORRECT_PASSWORD: "INCORRECT_PASSWORD";
|
|
156
|
+
readonly EMAIL_IN_USE: "EMAIL_IN_USE";
|
|
157
|
+
readonly INVALID_EMAIL: "INVALID_EMAIL";
|
|
158
|
+
readonly PASSWORD_TOO_SHORT: "PASSWORD_TOO_SHORT";
|
|
159
|
+
readonly PASSWORD_TOO_LONG: "PASSWORD_TOO_LONG";
|
|
160
|
+
readonly PASSWORD_NOT_ALLOWED: "PASSWORD_NOT_ALLOWED";
|
|
161
|
+
readonly UNKNOWN: "UNKNOWN";
|
|
162
|
+
};
|
|
163
|
+
type CredentialError = ObjectValues<typeof CREDENTIAL_ERROR>;
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/extensions/account-settings/context-providers/account-settings-context.d.ts
|
|
166
|
+
declare const SECTION_KIND: {
|
|
167
|
+
readonly GENERAL: "GENERAL";
|
|
168
|
+
readonly DISPLAY_INFO: "DISPLAY_INFO";
|
|
169
|
+
readonly SOCIAL: "SOCIAL";
|
|
170
|
+
};
|
|
171
|
+
type SectionKind = ObjectValues<typeof SECTION_KIND>;
|
|
172
|
+
declare const FIELD_KIND: {
|
|
173
|
+
readonly TEXT: "TEXT";
|
|
174
|
+
readonly NUMBER: "NUMBER";
|
|
175
|
+
readonly DATE: "DATE";
|
|
176
|
+
readonly URL: "URL";
|
|
177
|
+
readonly SOCIAL: "SOCIAL";
|
|
178
|
+
readonly CHOICE: "CHOICE";
|
|
179
|
+
readonly PHONE: "PHONE";
|
|
180
|
+
};
|
|
181
|
+
type FieldKind = MemberFieldType;
|
|
182
|
+
type ChoiceOption = MemberFieldOption;
|
|
183
|
+
type AccountFieldInputEvent = MemberFieldInputEvent;
|
|
184
|
+
interface AccountField {
|
|
185
|
+
id: string;
|
|
186
|
+
key: string;
|
|
187
|
+
kind: FieldKind;
|
|
188
|
+
isRequired: boolean;
|
|
189
|
+
isReadOnly: boolean;
|
|
190
|
+
label: string;
|
|
191
|
+
socialType: string | null;
|
|
192
|
+
loadedValue: string;
|
|
193
|
+
value: string;
|
|
194
|
+
isChanged: boolean;
|
|
195
|
+
options: ChoiceOption[] | null;
|
|
196
|
+
}
|
|
197
|
+
interface AccountFieldSection {
|
|
198
|
+
kind: SectionKind;
|
|
199
|
+
index: number;
|
|
200
|
+
fields: AccountField[];
|
|
201
|
+
}
|
|
202
|
+
interface AccountWriteState {
|
|
203
|
+
isSaving: boolean;
|
|
204
|
+
error: CredentialError | null;
|
|
205
|
+
}
|
|
206
|
+
/** The logged-in member's account details, their editing state and the writes that change them. */
|
|
207
|
+
interface AccountSettingsContextValue extends NamedAccountFields {
|
|
208
|
+
isLoading: boolean;
|
|
209
|
+
/** Bumped on every Save refused for an invalid field, so the topmost invalid input takes focus. */
|
|
210
|
+
focusRequest: number;
|
|
211
|
+
updateNamedField: (fieldName: string, event: MemberFieldInputEvent) => void;
|
|
212
|
+
/** `undefined` until a read commits, `null` with no member. */
|
|
213
|
+
loginEmail: string | null | undefined;
|
|
214
|
+
/** `undefined` until a read commits, `null` with no member. */
|
|
215
|
+
credentialRestriction: CredentialRestriction | null | undefined;
|
|
216
|
+
credentialSaving: boolean;
|
|
217
|
+
credentialError: CredentialError | null;
|
|
218
|
+
credentialDialog: CredentialDialog | null;
|
|
219
|
+
openChangeLoginEmailDialog: () => void;
|
|
220
|
+
openChangePasswordDialog: () => void;
|
|
221
|
+
/** @internal Read by the credential units; a page Button cannot close their modal dialog. */
|
|
222
|
+
closeCredentialDialog: () => void;
|
|
223
|
+
/** Resolves `true` once the member's changes are saved and re-read, `false` when nothing was saved. */
|
|
224
|
+
savePersonalInfo: () => Promise<boolean>;
|
|
225
|
+
/**
|
|
226
|
+
* @internal Read by the credential units, since a page Button cannot supply the passwords.
|
|
227
|
+
* Resolves `true` once the write lands, `false` on failure, refusal or a member change.
|
|
228
|
+
*/
|
|
229
|
+
changeLoginEmail: (newEmail: string, currentPassword: string) => Promise<boolean>;
|
|
230
|
+
/** @internal As `changeLoginEmail`. */
|
|
231
|
+
changePassword: (currentPassword: string, newPassword: string) => Promise<boolean>;
|
|
232
|
+
/** Resolves `true` once the email is sent, `false` on failure, refusal or a member change. */
|
|
233
|
+
sendSetPasswordEmail: () => Promise<boolean>;
|
|
234
|
+
}
|
|
235
|
+
declare const AccountSettingsContext: React.Context<AccountSettingsContextValue | null>;
|
|
236
|
+
/**
|
|
237
|
+
* Reads the Account Details context. Returns `null` when no provider is attached, so a consumer can
|
|
238
|
+
* collapse instead of crashing the page it was dropped onto.
|
|
239
|
+
*/
|
|
240
|
+
declare const useAccountSettings: () => AccountSettingsContextValue | null;
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/extensions/account-settings/context-providers/account-settings-context-provider.d.ts
|
|
243
|
+
/** Provides the logged-in member's account details and the writes that change them to its children. */
|
|
244
|
+
declare const AccountSettingsContextProvider: FC<PropsWithChildren>;
|
|
245
|
+
|
|
246
|
+
export { AccountSettingsContextProvider as AccountDetailsContextProvider, type AccountField, type AccountFieldInputEvent, type AccountFieldSection, AccountSettingsContext, type AccountSettingsContextValue, type AccountWriteState, CREDENTIAL_DIALOG, CREDENTIAL_ERROR, type ChoiceOption, type CredentialDialog, type CredentialError, FIELD_KIND, type FieldKind, NAMED_FIELD_KEYS, type NamedAccountFields, type NamedFieldBinding, SECTION_KIND, type SectionKind, AccountSettingsContextProvider as default, useAccountSettings };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { FC, PropsWithChildren, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
//#region src/extensions/account-home/context-providers/member-details.d.ts
|
|
4
|
+
/** The logged-in member, named after `@wix/members` `Member`; `null` when nobody is logged in. */
|
|
5
|
+
interface AccountHomeMember {
|
|
6
|
+
contact: {
|
|
7
|
+
firstName: string | null;
|
|
8
|
+
};
|
|
9
|
+
profile: {
|
|
10
|
+
nickname: string | null;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/extensions/account-home/context-providers/account-home-context-provider.d.ts
|
|
15
|
+
/** The Account Home page's state, for its greeting and Member Activity. */
|
|
16
|
+
interface AccountHomeContextValue {
|
|
17
|
+
/** @internal */
|
|
18
|
+
member: AccountHomeMember | null;
|
|
19
|
+
/** Whether Member Activity holds any card whose app is installed; `undefined` until known. */
|
|
20
|
+
hasInstalledPromoCards: boolean | undefined;
|
|
21
|
+
/** Whether any card in Member Activity shows something once read; `undefined` until known. */
|
|
22
|
+
hasPromoCardContent: boolean | undefined;
|
|
23
|
+
}
|
|
24
|
+
type PromoScopeProps = PropsWithChildren<{
|
|
25
|
+
onOccupancyChange?: (occupied: boolean) => void; /** Shown while the scope's content suspends; the scope has not reported until it commits. */
|
|
26
|
+
fallback?: ReactNode;
|
|
27
|
+
}>;
|
|
28
|
+
interface PromoCardOptions {
|
|
29
|
+
promoCard: true;
|
|
30
|
+
}
|
|
31
|
+
interface PromoCardRegistration {
|
|
32
|
+
/** False while any card on the page is still loading; a card holds its skeleton until then. */
|
|
33
|
+
revealed: boolean;
|
|
34
|
+
/** Reports the card's read as settled, whatever it resolved to. */
|
|
35
|
+
settle: () => void;
|
|
36
|
+
/** Reports that the card shows something, until the returned callback is called. */
|
|
37
|
+
showContent: () => () => void;
|
|
38
|
+
}
|
|
39
|
+
interface PromoScopeOptions {
|
|
40
|
+
promoScope: true;
|
|
41
|
+
}
|
|
42
|
+
type AccountHomeHookOptions = PromoCardOptions | PromoScopeOptions;
|
|
43
|
+
/**
|
|
44
|
+
* Reads the Account Home context. With no options it returns the context value and suspends until
|
|
45
|
+
* the logged-in member is read; `promoCard` registers the calling card and `promoScope` returns the
|
|
46
|
+
* Member Activity scope, and neither waits on the member read or requires an attached provider.
|
|
47
|
+
*/
|
|
48
|
+
declare function useAccountHome(): AccountHomeContextValue;
|
|
49
|
+
declare function useAccountHome(options: PromoCardOptions): PromoCardRegistration;
|
|
50
|
+
declare function useAccountHome(options: PromoScopeOptions): FC<PromoScopeProps>;
|
|
51
|
+
/** Provides the logged-in member and whether Member Activity holds an installed card to its children. */
|
|
52
|
+
declare const AccountHomeContextProvider: FC<PropsWithChildren>;
|
|
53
|
+
|
|
54
|
+
export { AccountHomeContextProvider, type AccountHomeContextValue, type AccountHomeHookOptions, type AccountHomeMember, type PromoCardOptions, type PromoCardRegistration, type PromoScopeOptions, type PromoScopeProps, AccountHomeContextProvider as default, useAccountHome };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React__default, { FC, PropsWithChildren } from 'react';
|
|
2
|
+
|
|
3
|
+
//#region src/extensions/my-addresses/context-providers/my-addresses-context-provider/my-addresses.types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* One saved address, the `@wix/members` Address flattened onto the row so a row element binds each
|
|
6
|
+
* part directly, every absent part `null` (`CTX-25`). `recipient.*` keeps its leaf names, and
|
|
7
|
+
* `streetAddress.name` and `.number` become `streetName` and `streetNumber`.
|
|
8
|
+
*/
|
|
9
|
+
interface MemberAddressFields {
|
|
10
|
+
_id: string;
|
|
11
|
+
firstName: string | null;
|
|
12
|
+
lastName: string | null;
|
|
13
|
+
/** @internal No unit draws it; only the edit form reads it. */
|
|
14
|
+
company: string | null;
|
|
15
|
+
phone: string | null;
|
|
16
|
+
/** Empty when the address is stored as a street name and number instead. */
|
|
17
|
+
addressLine: string | null;
|
|
18
|
+
streetName: string | null;
|
|
19
|
+
streetNumber: string | null;
|
|
20
|
+
addressLine2: string | null;
|
|
21
|
+
city: string | null;
|
|
22
|
+
/** The ISO 3166-2 code, as `US-CA`. */
|
|
23
|
+
subdivision: string | null;
|
|
24
|
+
/** The ISO 3166-1 alpha-2 code. */
|
|
25
|
+
country: string | null;
|
|
26
|
+
postalCode: string | null;
|
|
27
|
+
savedDefault: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** Each change resolves `true` once the list shows it and `false` after its error toast, never rejecting. */
|
|
30
|
+
interface AddressActions {
|
|
31
|
+
onSetDefault: () => Promise<boolean>;
|
|
32
|
+
onRemove: () => Promise<boolean>;
|
|
33
|
+
/** Opens the address form's edit session for this address. */
|
|
34
|
+
onEdit: () => void;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/extensions/my-addresses/context-providers/address-context-provider/address-context-provider.d.ts
|
|
38
|
+
/** One row's address and the list's own actions on it, which take no identifier. */
|
|
39
|
+
type AddressContextValue = MemberAddressFields & AddressActions;
|
|
40
|
+
declare const AddressContext: React__default.Context<AddressContextValue | null>;
|
|
41
|
+
/** Reads the Address context of the row it renders in; throws outside its provider unless `optional`, which returns `null` there. */
|
|
42
|
+
declare function useAddress(): AddressContextValue;
|
|
43
|
+
declare function useAddress(options: {
|
|
44
|
+
optional: true;
|
|
45
|
+
}): AddressContextValue | null;
|
|
46
|
+
interface AddressContextProviderProps {
|
|
47
|
+
addressData: AddressContextValue;
|
|
48
|
+
}
|
|
49
|
+
/** Provides one saved address and its actions to a list row, delegated per row by My Addresses. */
|
|
50
|
+
declare const AddressContextProvider: FC<PropsWithChildren<AddressContextProviderProps>>;
|
|
51
|
+
|
|
52
|
+
export { AddressContext, AddressContextProvider, type AddressContextProviderProps, type AddressContextValue, type MemberAddressFields, AddressContextProvider as default, useAddress };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { FC, PropsWithChildren } from 'react';
|
|
2
|
+
|
|
3
|
+
//#region src/extensions/my-addresses/context-providers/my-addresses-context-provider/my-addresses.types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* One saved address, the `@wix/members` Address flattened onto the row so a row element binds each
|
|
6
|
+
* part directly, every absent part `null` (`CTX-25`). `recipient.*` keeps its leaf names, and
|
|
7
|
+
* `streetAddress.name` and `.number` become `streetName` and `streetNumber`.
|
|
8
|
+
*/
|
|
9
|
+
interface MemberAddressFields {
|
|
10
|
+
_id: string;
|
|
11
|
+
firstName: string | null;
|
|
12
|
+
lastName: string | null;
|
|
13
|
+
/** @internal No unit draws it; only the edit form reads it. */
|
|
14
|
+
company: string | null;
|
|
15
|
+
phone: string | null;
|
|
16
|
+
/** Empty when the address is stored as a street name and number instead. */
|
|
17
|
+
addressLine: string | null;
|
|
18
|
+
streetName: string | null;
|
|
19
|
+
streetNumber: string | null;
|
|
20
|
+
addressLine2: string | null;
|
|
21
|
+
city: string | null;
|
|
22
|
+
/** The ISO 3166-2 code, as `US-CA`. */
|
|
23
|
+
subdivision: string | null;
|
|
24
|
+
/** The ISO 3166-1 alpha-2 code. */
|
|
25
|
+
country: string | null;
|
|
26
|
+
postalCode: string | null;
|
|
27
|
+
savedDefault: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** Each change resolves `true` once the list shows it and `false` after its error toast, never rejecting. */
|
|
30
|
+
interface AddressActions {
|
|
31
|
+
onSetDefault: () => Promise<boolean>;
|
|
32
|
+
onRemove: () => Promise<boolean>;
|
|
33
|
+
/** Opens the address form's edit session for this address. */
|
|
34
|
+
onEdit: () => void;
|
|
35
|
+
}
|
|
36
|
+
/** The actions ride on the list's item, which is what the platform hands each delegated row. */
|
|
37
|
+
type MemberAddress = MemberAddressFields & AddressActions;
|
|
38
|
+
/** The address form's one open session: empty to add an address, or filled in to edit one. */
|
|
39
|
+
type AddressFormSession = {
|
|
40
|
+
mode: 'add';
|
|
41
|
+
} | {
|
|
42
|
+
mode: 'edit';
|
|
43
|
+
address: AddressFormValues & {
|
|
44
|
+
savedDefault: boolean;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/** The logged-in member's address book, for the My Addresses page's list and Add Address. */
|
|
48
|
+
interface AddressesContextValue {
|
|
49
|
+
/** Every saved address, the default first. */
|
|
50
|
+
addresses: MemberAddress[];
|
|
51
|
+
/** A boolean because a visibility condition compares its binding to one exactly. */
|
|
52
|
+
hasAddresses: boolean;
|
|
53
|
+
/** True until the first address query has settled; the Repeater's `isLoading` takes a boolean. */
|
|
54
|
+
isLoading: boolean;
|
|
55
|
+
/** Opens the address form's add session. */
|
|
56
|
+
onAddAddress: () => void;
|
|
57
|
+
/** @internal The open form session, `null` while the form is closed. */
|
|
58
|
+
addressForm: AddressFormSession | null;
|
|
59
|
+
/** @internal Ends the form session, saving nothing. */
|
|
60
|
+
closeAddressForm: () => void;
|
|
61
|
+
/**
|
|
62
|
+
* @internal Saves the session's address, resolving once the list draws it and rejecting when the
|
|
63
|
+
* save failed (`GEN-13`).
|
|
64
|
+
*/
|
|
65
|
+
saveAddress: (values: AddressFormValues, setAsDefault: boolean) => Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
/** What the address form edits and saves, each part as typed and `''` when left empty. */
|
|
68
|
+
interface AddressFormValues {
|
|
69
|
+
firstName: string;
|
|
70
|
+
lastName: string;
|
|
71
|
+
company: string;
|
|
72
|
+
/** The ISO 3166-1 alpha-2 code. */
|
|
73
|
+
country: string;
|
|
74
|
+
/** The ISO 3166-2 code, as `US-CA`. */
|
|
75
|
+
subdivision: string;
|
|
76
|
+
city: string;
|
|
77
|
+
addressLine: string;
|
|
78
|
+
addressLine2: string;
|
|
79
|
+
streetName: string;
|
|
80
|
+
streetNumber: string;
|
|
81
|
+
postalCode: string;
|
|
82
|
+
phone: string;
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/extensions/my-addresses/context-providers/my-addresses-context-provider/my-addresses-context.d.ts
|
|
86
|
+
/** Reads the Addresses context; throws outside its provider unless `optional`, which returns `null` there. */
|
|
87
|
+
declare function useAddresses(): AddressesContextValue;
|
|
88
|
+
declare function useAddresses(options: {
|
|
89
|
+
optional: true;
|
|
90
|
+
}): AddressesContextValue | null;
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/extensions/my-addresses/context-providers/my-addresses-context-provider/my-addresses-context-provider.d.ts
|
|
93
|
+
type FormActions = Pick<AddressesContextValue, 'onAddAddress' | 'addressForm' | 'closeAddressForm' | 'saveAddress'>;
|
|
94
|
+
declare function toContextValue(addresses: MemberAddress[], formActions: FormActions): AddressesContextValue;
|
|
95
|
+
interface RowActions {
|
|
96
|
+
setDefault: (id: string) => Promise<boolean>;
|
|
97
|
+
remove: (address: MemberAddress) => Promise<boolean>;
|
|
98
|
+
edit: (address: MemberAddress) => void;
|
|
99
|
+
}
|
|
100
|
+
declare function toMemberAddresses(book: MemberAddressFields[], actions: RowActions): MemberAddress[];
|
|
101
|
+
/** Provides the logged-in member's saved addresses, and the actions that add and change them, to its children. */
|
|
102
|
+
declare const MyAddressesContextProvider: FC<PropsWithChildren>;
|
|
103
|
+
|
|
104
|
+
export { type AddressActions, type AddressFormSession, type AddressFormValues, MyAddressesContextProvider as AddressesContextProvider, type AddressesContextValue, type MemberAddress, type MemberAddressFields, MyAddressesContextProvider as default, toContextValue, toMemberAddresses, useAddresses };
|