@planningcenter/organization-avatars 1.8.4 → 1.10.0
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/dist/index.cjs +1 -1
- package/dist/index.js +300 -398
- package/dist/test-setup.d.ts +1 -0
- package/package.json +18 -11
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`react`),l=require(`react-dom`),u=require(`@planningcenter/url`),d=require(`@planningcenter/tapestry`),f=require(`@planningcenter/sweetest-alert`),p=require(`@planningcenter/icons/paths/general`),m=require(`@planningcenter/icons/paths/services`),h=require(`react-dropzone`);h=s(h,1);let g=require(`react/jsx-runtime`);function _(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`)if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=_(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n);return r}function v(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=_(e))&&(r&&(r+=` `),r+=t);return r}function y(){let e=document.querySelector(`meta[name="csrf-token"]`);if(!e||!e.content)throw Error(`CSRF token not found. Ensure your Rails application includes <meta name="csrf-token" content="..."> in the document head.`);return e.content}function b(e){let t=e.split(``);return[t.shift()?.toUpperCase(),t.join(``)].join(``)}var x=e=>e===`dark_mode_avatar`?`dark`:`light`,S=({open:e})=>(0,g.jsxs)(`h2`,{className:`pco-org-avatar__instructions`,children:[`Drag & drop your logo file to upload, or`,` `,(0,g.jsx)(d.Button,{label:`browse`,kind:`inline-text`,onClick:t=>{t.stopPropagation(),e()}})]});function C({avatarUrl:e,organization:t,mode:n,pcoEnv:r,readOnly:i,onAvatarUpdate:a,fallbackAvatarUrl:o}){let[s,_]=(0,c.useState)(null),[C,w]=(0,c.useState)(!1),[T,E]=(0,c.useState)(!1),[D,O]=(0,c.useState)(``),k=(0,c.useId)(),A=(0,c.useRef)(null),j=x(n),M=e||o,N=e=>{let[t]=e;t&&_(Object.assign(t,{preview:URL.createObjectURL(t)}))};(0,c.useEffect)(()=>()=>{s?.preview&&(URL.revokeObjectURL(s.preview),O(``))},[s]);let P=async e=>{let t=await fetch((0,u.pcoApiUrl)(`accounts`,{env:r}),{method:`PATCH`,headers:{"Content-Type":`application/json`,"X-CSRF-Token":y(),Accept:`application/json`},body:JSON.stringify({data:{attributes:e}})}),n=await t.json();if(!t.ok)throw n;return n},F=async e=>{if(e.preventDefault(),!(!s||C||T)){w(!0);try{let e=new FileReader,t=await new Promise((t,n)=>{e.onloadend=()=>t(e.result),e.onerror=n,e.readAsDataURL(s)}),r=await P({[n]:t,[`${n}_cache`]:``});_(null),a(n,r.data.attributes[n].url),A.current?.close()}catch{O(`We were unable to save your avatar.`)}finally{w(!1)}}},I=async()=>{C||T||(E(!0),(0,f.SweetestAlert)({type:`danger`,title:`Remove this logo?`,content:j===`light`?`Removing this logo means no logo will appear in light mode. This cannot be undone.`:o?`Removing this logo means your light mode logo will appear in dark mode. This cannot be undone.`:`Removing this logo means no logo will appear in dark mode. This cannot be undone.`,confirmButton:`Remove logo`,onConfirm:async()=>{try{await P({[`remove_${n}`]:`1`}),a(n,``),A.current?.close()}catch{O(`We were unable to delete your avatar.`)}finally{E(!1)}},onCancel:()=>{E(!1)}}))};return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`div`,{className:`pco-org-avatar`,children:[(0,g.jsx)(`button`,{type:`button`,onClick:()=>A.current?.showModal(),disabled:i,className:`pco-org-avatar__button pco-org-avatar__button--${j}`,children:M?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`img`,{src:M,alt:`Church logo for ${t}`}),(0,g.jsx)(`div`,{className:`tds-btn tds-btn--interaction tds-btn--icononly`,children:(0,g.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 16 16`,fill:`currentColor`,"aria-hidden":`true`,children:(0,g.jsx)(`path`,{d:p.pencil})})})]}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`svg`,{width:`48`,height:`48`,viewBox:`0 0 16 16`,fill:`currentColor`,"aria-hidden":`true`,children:(0,g.jsx)(`path`,{d:m.image})}),(0,g.jsx)(`div`,{className:`tds-btn tds-btn--interaction tds-btn--icononly`,children:(0,g.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 16 16`,fill:`currentColor`,"aria-hidden":`true`,children:(0,g.jsx)(`path`,{d:p.pencil})})})]})}),(0,g.jsxs)(`div`,{className:`pco-org-avatar__label`,children:[b(j),` mode`]})]}),(0,l.createPortal)((0,g.jsx)(`dialog`,{id:k,ref:A,className:`pco-org-avatar__dialog`,onClose:()=>{_(null),O(``)},children:(0,g.jsxs)(`form`,{onSubmit:F,children:[(0,g.jsxs)(`div`,{className:`pco-org-avatar__dialog-header`,children:[(0,g.jsxs)(`h1`,{className:`pco-org-avatar__dialog-title`,children:[`Church logo — `,j,` mode`]}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>A.current?.close(),className:`pco-org-avatar__dialog-close`,"aria-label":`Close modal`,children:(0,g.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`currentColor`,"aria-hidden":`true`,children:(0,g.jsx)(`path`,{d:p.smallX})})})]}),(0,g.jsxs)(`div`,{className:`pco-org-avatar__dialog-body`,children:[D&&(0,g.jsxs)(`div`,{role:`alert`,className:`pco-org-avatar-alert pco-org-avatar__dialog-alert`,children:[(0,g.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,className:`symbol`,"aria-hidden":`true`,children:(0,g.jsx)(`path`,{d:p.exclamationTriangle})}),(0,g.jsx)(`p`,{children:D})]}),(0,g.jsx)(h.default,{accept:{"image/*":[`.jpg`,`.jpeg`,`.png`]},multiple:!1,onDropAccepted:N,children:({getRootProps:e,getInputProps:n,isFocused:r,isDragAccept:i,isDragReject:a,isDragActive:o,open:c})=>(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`div`,{...e({className:v(`pco-org-avatar__dialog-dropzone`,`pco-org-avatar__dialog-dropzone--${j}`,{"pco-org-avatar__dialog-dropzone--image":s||M,"pco-org-avatar__dialog-dropzone--focused":r,"pco-org-avatar__dialog-dropzone--accepted":i,"pco-org-avatar__dialog-dropzone--rejected":o&&a})}),children:[(0,g.jsx)(`input`,{...n()}),s?(0,g.jsx)(`img`,{src:s.preview,alt:`Church logo for ${t}`}):M?(0,g.jsx)(`img`,{src:M,alt:`Church logo for ${t}`}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`svg`,{width:`64`,height:`64`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,g.jsx)(`path`,{d:p.toCloudArrow})}),o&&a?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`h2`,{children:`Wrong file type`}),(0,g.jsx)(`p`,{children:`Please upload a PNG or JPG file.`})]}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(S,{open:c}),(0,g.jsx)(`p`,{className:`pco-org-avatar__instructions-sub`,children:`Use a high-quality image (up to 20mb) with a transparent background.`})]})]})]}),(s||M)&&(0,g.jsx)(S,{open:c})]})})]}),(0,g.jsxs)(`div`,{className:`pco-org-avatar__dialog-actions`,children:[e&&j===`light`&&(0,g.jsx)(d.Button,{label:`Remove logo`,kind:`secondary-delete`,onClick:I,loading:T,disabled:T||C,className:`pco-org-avatar__dialog-delete`}),e&&j===`dark`&&(0,g.jsx)(d.Button,{label:`Use light mode logo`,kind:`secondary`,onClick:I,loading:T,disabled:T||C,className:`pco-org-avatar__dialog-delete`}),(0,g.jsx)(d.Button,{type:`button`,label:`Cancel`,onClick:()=>A.current?.close(),disabled:C||T}),(0,g.jsx)(d.Button,{type:`submit`,label:`Update logo`,kind:`primary`,loading:C,disabled:!s||C||T})]})]})}),document.body)]})}function w({avatarUrl:e,darkModeAvatarUrl:t,orgName:n,onAvatarUpdate:r,pcoEnv:i,readOnly:a,showDarkModeAvatar:o=!1}){let[s,l]=(0,c.useState)(e),[u,d]=(0,c.useState)(t),f=(e,t)=>{e===`avatar`?(l(t),r?.(`avatar`,t)):e===`dark_mode_avatar`&&(d(t),r?.(`dark_mode_avatar`,t))};return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`div`,{className:`pco-org-avatars`,children:[(0,g.jsx)(C,{avatarUrl:s,organization:n,mode:`avatar`,pcoEnv:i,readOnly:a,onAvatarUpdate:f}),o&&(0,g.jsx)(C,{avatarUrl:u,organization:n,mode:`dark_mode_avatar`,pcoEnv:i,readOnly:a,onAvatarUpdate:f,fallbackAvatarUrl:s})]}),o&&s&&!u&&(0,g.jsxs)(`div`,{className:`pco-org-avatar-alert`,children:[(0,g.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,className:`symbol`,"aria-hidden":`true`,children:(0,g.jsx)(`path`,{d:p.infoCircle})}),(0,g.jsx)(`p`,{children:`The same logo is being used for both light and dark modes.`})]})]})}exports.OrganizationAvatars=w;
|
package/dist/index.js
CHANGED
|
@@ -1,404 +1,306 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { useEffect as e, useId as t, useRef as n, useState as r } from "react";
|
|
2
|
+
import { createPortal as i } from "react-dom";
|
|
3
|
+
import { pcoApiUrl as a } from "@planningcenter/url";
|
|
4
|
+
import { Button as o } from "@planningcenter/tapestry";
|
|
5
|
+
import { SweetestAlert as s } from "@planningcenter/sweetest-alert";
|
|
6
|
+
import { exclamationTriangle as c, infoCircle as l, pencil as u, smallX as d, toCloudArrow as f } from "@planningcenter/icons/paths/general";
|
|
7
|
+
import { image as p } from "@planningcenter/icons/paths/services";
|
|
8
|
+
import m from "react-dropzone";
|
|
9
|
+
import { Fragment as h, jsx as g, jsxs as _ } from "react/jsx-runtime";
|
|
10
|
+
//#region node_modules/clsx/dist/clsx.mjs
|
|
11
|
+
function v(e) {
|
|
12
|
+
var t, n, r = "";
|
|
13
|
+
if (typeof e == "string" || typeof e == "number") r += e;
|
|
14
|
+
else if (typeof e == "object") if (Array.isArray(e)) {
|
|
15
|
+
var i = e.length;
|
|
16
|
+
for (t = 0; t < i; t++) e[t] && (n = v(e[t])) && (r && (r += " "), r += n);
|
|
17
|
+
} else for (n in e) e[n] && (r && (r += " "), r += n);
|
|
18
|
+
return r;
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
function y() {
|
|
21
|
+
for (var e, t, n = 0, r = "", i = arguments.length; n < i; n++) (e = arguments[n]) && (t = v(e)) && (r && (r += " "), r += t);
|
|
22
|
+
return r;
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return a.content;
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/utils.ts
|
|
26
|
+
function b() {
|
|
27
|
+
let e = document.querySelector("meta[name=\"csrf-token\"]");
|
|
28
|
+
if (!e || !e.content) throw Error("CSRF token not found. Ensure your Rails application includes <meta name=\"csrf-token\" content=\"...\"> in the document head.");
|
|
29
|
+
return e.content;
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
function x(e) {
|
|
32
|
+
let t = e.split("");
|
|
33
|
+
return [t.shift()?.toUpperCase(), t.join("")].join("");
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
alt: `Church logo for ${t}`
|
|
269
|
-
}
|
|
270
|
-
) : /* @__PURE__ */ r(h, { children: [
|
|
271
|
-
/* @__PURE__ */ e(
|
|
272
|
-
"svg",
|
|
273
|
-
{
|
|
274
|
-
width: "64",
|
|
275
|
-
height: "64",
|
|
276
|
-
viewBox: "0 0 16 16",
|
|
277
|
-
"aria-hidden": "true",
|
|
278
|
-
children: /* @__PURE__ */ e("path", { d: K })
|
|
279
|
-
}
|
|
280
|
-
),
|
|
281
|
-
U && R ? /* @__PURE__ */ r(h, { children: [
|
|
282
|
-
/* @__PURE__ */ e("h2", { children: "Wrong file type" }),
|
|
283
|
-
/* @__PURE__ */ e("p", { children: "Please upload a PNG or JPG file." })
|
|
284
|
-
] }) : /* @__PURE__ */ r(h, { children: [
|
|
285
|
-
/* @__PURE__ */ e(B, { open: S }),
|
|
286
|
-
/* @__PURE__ */ e("p", { className: "pco-org-avatar__instructions-sub", children: "Use a high-quality image (up to 20mb) with a transparent background." })
|
|
287
|
-
] })
|
|
288
|
-
] })
|
|
289
|
-
] }),
|
|
290
|
-
(i || f) && /* @__PURE__ */ e(B, { open: S })
|
|
291
|
-
] });
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
)
|
|
295
|
-
] }),
|
|
296
|
-
/* @__PURE__ */ r("div", { className: "pco-org-avatar__dialog-actions", children: [
|
|
297
|
-
a && p === "light" && /* @__PURE__ */ e(
|
|
298
|
-
C,
|
|
299
|
-
{
|
|
300
|
-
label: "Remove logo",
|
|
301
|
-
kind: "secondary-delete",
|
|
302
|
-
onClick: z,
|
|
303
|
-
loading: c,
|
|
304
|
-
disabled: c || d,
|
|
305
|
-
className: "pco-org-avatar__dialog-delete"
|
|
306
|
-
}
|
|
307
|
-
),
|
|
308
|
-
a && p === "dark" && /* @__PURE__ */ e(
|
|
309
|
-
C,
|
|
310
|
-
{
|
|
311
|
-
label: "Use light mode logo",
|
|
312
|
-
kind: "secondary",
|
|
313
|
-
onClick: z,
|
|
314
|
-
loading: c,
|
|
315
|
-
disabled: c || d,
|
|
316
|
-
className: "pco-org-avatar__dialog-delete"
|
|
317
|
-
}
|
|
318
|
-
),
|
|
319
|
-
/* @__PURE__ */ e(
|
|
320
|
-
C,
|
|
321
|
-
{
|
|
322
|
-
type: "button",
|
|
323
|
-
label: "Cancel",
|
|
324
|
-
onClick: () => v.current?.close(),
|
|
325
|
-
disabled: d || c
|
|
326
|
-
}
|
|
327
|
-
),
|
|
328
|
-
/* @__PURE__ */ e(
|
|
329
|
-
C,
|
|
330
|
-
{
|
|
331
|
-
type: "submit",
|
|
332
|
-
label: "Update logo",
|
|
333
|
-
kind: "primary",
|
|
334
|
-
loading: d,
|
|
335
|
-
disabled: !i || d || c
|
|
336
|
-
}
|
|
337
|
-
)
|
|
338
|
-
] })
|
|
339
|
-
] })
|
|
340
|
-
}
|
|
341
|
-
),
|
|
342
|
-
document.body
|
|
343
|
-
)
|
|
344
|
-
] });
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/organization_avatar.tsx
|
|
37
|
+
var S = (e) => e === "dark_mode_avatar" ? "dark" : "light", C = ({ open: e }) => /* @__PURE__ */ _("h2", {
|
|
38
|
+
className: "pco-org-avatar__instructions",
|
|
39
|
+
children: [
|
|
40
|
+
"Drag & drop your logo file to upload, or",
|
|
41
|
+
" ",
|
|
42
|
+
/* @__PURE__ */ g(o, {
|
|
43
|
+
label: "browse",
|
|
44
|
+
kind: "inline-text",
|
|
45
|
+
onClick: (t) => {
|
|
46
|
+
t.stopPropagation(), e();
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
function w({ avatarUrl: l, organization: v, mode: w, pcoEnv: T, readOnly: E, onAvatarUpdate: D, fallbackAvatarUrl: O }) {
|
|
52
|
+
let [k, A] = r(null), [j, M] = r(!1), [N, P] = r(!1), [F, I] = r(""), L = t(), R = n(null), z = S(w), B = l || O, V = (e) => {
|
|
53
|
+
let [t] = e;
|
|
54
|
+
t && A(Object.assign(t, { preview: URL.createObjectURL(t) }));
|
|
55
|
+
};
|
|
56
|
+
e(() => () => {
|
|
57
|
+
k?.preview && (URL.revokeObjectURL(k.preview), I(""));
|
|
58
|
+
}, [k]);
|
|
59
|
+
let H = async (e) => {
|
|
60
|
+
let t = await fetch(a("accounts", { env: T }), {
|
|
61
|
+
method: "PATCH",
|
|
62
|
+
headers: {
|
|
63
|
+
"Content-Type": "application/json",
|
|
64
|
+
"X-CSRF-Token": b(),
|
|
65
|
+
Accept: "application/json"
|
|
66
|
+
},
|
|
67
|
+
body: JSON.stringify({ data: { attributes: e } })
|
|
68
|
+
}), n = await t.json();
|
|
69
|
+
if (!t.ok) throw n;
|
|
70
|
+
return n;
|
|
71
|
+
}, U = async (e) => {
|
|
72
|
+
if (e.preventDefault(), !(!k || j || N)) {
|
|
73
|
+
M(!0);
|
|
74
|
+
try {
|
|
75
|
+
let e = new FileReader(), t = await new Promise((t, n) => {
|
|
76
|
+
e.onloadend = () => t(e.result), e.onerror = n, e.readAsDataURL(k);
|
|
77
|
+
}), n = await H({
|
|
78
|
+
[w]: t,
|
|
79
|
+
[`${w}_cache`]: ""
|
|
80
|
+
});
|
|
81
|
+
A(null), D(w, n.data.attributes[w].url), R.current?.close();
|
|
82
|
+
} catch {
|
|
83
|
+
I("We were unable to save your avatar.");
|
|
84
|
+
} finally {
|
|
85
|
+
M(!1);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, W = async () => {
|
|
89
|
+
j || N || (P(!0), s({
|
|
90
|
+
type: "danger",
|
|
91
|
+
title: "Remove this logo?",
|
|
92
|
+
content: z === "light" ? "Removing this logo means no logo will appear in light mode. This cannot be undone." : O ? "Removing this logo means your light mode logo will appear in dark mode. This cannot be undone." : "Removing this logo means no logo will appear in dark mode. This cannot be undone.",
|
|
93
|
+
confirmButton: "Remove logo",
|
|
94
|
+
onConfirm: async () => {
|
|
95
|
+
try {
|
|
96
|
+
await H({ [`remove_${w}`]: "1" }), D(w, ""), R.current?.close();
|
|
97
|
+
} catch {
|
|
98
|
+
I("We were unable to delete your avatar.");
|
|
99
|
+
} finally {
|
|
100
|
+
P(!1);
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
onCancel: () => {
|
|
104
|
+
P(!1);
|
|
105
|
+
}
|
|
106
|
+
}));
|
|
107
|
+
};
|
|
108
|
+
return /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ _("div", {
|
|
109
|
+
className: "pco-org-avatar",
|
|
110
|
+
children: [/* @__PURE__ */ g("button", {
|
|
111
|
+
type: "button",
|
|
112
|
+
onClick: () => R.current?.showModal(),
|
|
113
|
+
disabled: E,
|
|
114
|
+
className: `pco-org-avatar__button pco-org-avatar__button--${z}`,
|
|
115
|
+
children: B ? /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ g("img", {
|
|
116
|
+
src: B,
|
|
117
|
+
alt: `Church logo for ${v}`
|
|
118
|
+
}), /* @__PURE__ */ g("div", {
|
|
119
|
+
className: "tds-btn tds-btn--interaction tds-btn--icononly",
|
|
120
|
+
children: /* @__PURE__ */ g("svg", {
|
|
121
|
+
width: "14",
|
|
122
|
+
height: "14",
|
|
123
|
+
viewBox: "0 0 16 16",
|
|
124
|
+
fill: "currentColor",
|
|
125
|
+
"aria-hidden": "true",
|
|
126
|
+
children: /* @__PURE__ */ g("path", { d: u })
|
|
127
|
+
})
|
|
128
|
+
})] }) : /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ g("svg", {
|
|
129
|
+
width: "48",
|
|
130
|
+
height: "48",
|
|
131
|
+
viewBox: "0 0 16 16",
|
|
132
|
+
fill: "currentColor",
|
|
133
|
+
"aria-hidden": "true",
|
|
134
|
+
children: /* @__PURE__ */ g("path", { d: p })
|
|
135
|
+
}), /* @__PURE__ */ g("div", {
|
|
136
|
+
className: "tds-btn tds-btn--interaction tds-btn--icononly",
|
|
137
|
+
children: /* @__PURE__ */ g("svg", {
|
|
138
|
+
width: "14",
|
|
139
|
+
height: "14",
|
|
140
|
+
viewBox: "0 0 16 16",
|
|
141
|
+
fill: "currentColor",
|
|
142
|
+
"aria-hidden": "true",
|
|
143
|
+
children: /* @__PURE__ */ g("path", { d: u })
|
|
144
|
+
})
|
|
145
|
+
})] })
|
|
146
|
+
}), /* @__PURE__ */ _("div", {
|
|
147
|
+
className: "pco-org-avatar__label",
|
|
148
|
+
children: [x(z), " mode"]
|
|
149
|
+
})]
|
|
150
|
+
}), i(/* @__PURE__ */ g("dialog", {
|
|
151
|
+
id: L,
|
|
152
|
+
ref: R,
|
|
153
|
+
className: "pco-org-avatar__dialog",
|
|
154
|
+
onClose: () => {
|
|
155
|
+
A(null), I("");
|
|
156
|
+
},
|
|
157
|
+
children: /* @__PURE__ */ _("form", {
|
|
158
|
+
onSubmit: U,
|
|
159
|
+
children: [
|
|
160
|
+
/* @__PURE__ */ _("div", {
|
|
161
|
+
className: "pco-org-avatar__dialog-header",
|
|
162
|
+
children: [/* @__PURE__ */ _("h1", {
|
|
163
|
+
className: "pco-org-avatar__dialog-title",
|
|
164
|
+
children: [
|
|
165
|
+
"Church logo — ",
|
|
166
|
+
z,
|
|
167
|
+
" mode"
|
|
168
|
+
]
|
|
169
|
+
}), /* @__PURE__ */ g("button", {
|
|
170
|
+
type: "button",
|
|
171
|
+
onClick: () => R.current?.close(),
|
|
172
|
+
className: "pco-org-avatar__dialog-close",
|
|
173
|
+
"aria-label": "Close modal",
|
|
174
|
+
children: /* @__PURE__ */ g("svg", {
|
|
175
|
+
width: "16",
|
|
176
|
+
height: "16",
|
|
177
|
+
viewBox: "0 0 16 16",
|
|
178
|
+
fill: "currentColor",
|
|
179
|
+
"aria-hidden": "true",
|
|
180
|
+
children: /* @__PURE__ */ g("path", { d })
|
|
181
|
+
})
|
|
182
|
+
})]
|
|
183
|
+
}),
|
|
184
|
+
/* @__PURE__ */ _("div", {
|
|
185
|
+
className: "pco-org-avatar__dialog-body",
|
|
186
|
+
children: [F && /* @__PURE__ */ _("div", {
|
|
187
|
+
role: "alert",
|
|
188
|
+
className: "pco-org-avatar-alert pco-org-avatar__dialog-alert",
|
|
189
|
+
children: [/* @__PURE__ */ g("svg", {
|
|
190
|
+
width: "16",
|
|
191
|
+
height: "16",
|
|
192
|
+
viewBox: "0 0 16 16",
|
|
193
|
+
className: "symbol",
|
|
194
|
+
"aria-hidden": "true",
|
|
195
|
+
children: /* @__PURE__ */ g("path", { d: c })
|
|
196
|
+
}), /* @__PURE__ */ g("p", { children: F })]
|
|
197
|
+
}), /* @__PURE__ */ g(m, {
|
|
198
|
+
accept: { "image/*": [
|
|
199
|
+
".jpg",
|
|
200
|
+
".jpeg",
|
|
201
|
+
".png"
|
|
202
|
+
] },
|
|
203
|
+
multiple: !1,
|
|
204
|
+
onDropAccepted: V,
|
|
205
|
+
children: ({ getRootProps: e, getInputProps: t, isFocused: n, isDragAccept: r, isDragReject: i, isDragActive: a, open: o }) => /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ _("div", {
|
|
206
|
+
...e({ className: y("pco-org-avatar__dialog-dropzone", `pco-org-avatar__dialog-dropzone--${z}`, {
|
|
207
|
+
"pco-org-avatar__dialog-dropzone--image": k || B,
|
|
208
|
+
"pco-org-avatar__dialog-dropzone--focused": n,
|
|
209
|
+
"pco-org-avatar__dialog-dropzone--accepted": r,
|
|
210
|
+
"pco-org-avatar__dialog-dropzone--rejected": a && i
|
|
211
|
+
}) }),
|
|
212
|
+
children: [/* @__PURE__ */ g("input", { ...t() }), k ? /* @__PURE__ */ g("img", {
|
|
213
|
+
src: k.preview,
|
|
214
|
+
alt: `Church logo for ${v}`
|
|
215
|
+
}) : B ? /* @__PURE__ */ g("img", {
|
|
216
|
+
src: B,
|
|
217
|
+
alt: `Church logo for ${v}`
|
|
218
|
+
}) : /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ g("svg", {
|
|
219
|
+
width: "64",
|
|
220
|
+
height: "64",
|
|
221
|
+
viewBox: "0 0 16 16",
|
|
222
|
+
"aria-hidden": "true",
|
|
223
|
+
children: /* @__PURE__ */ g("path", { d: f })
|
|
224
|
+
}), a && i ? /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ g("h2", { children: "Wrong file type" }), /* @__PURE__ */ g("p", { children: "Please upload a PNG or JPG file." })] }) : /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ g(C, { open: o }), /* @__PURE__ */ g("p", {
|
|
225
|
+
className: "pco-org-avatar__instructions-sub",
|
|
226
|
+
children: "Use a high-quality image (up to 20mb) with a transparent background."
|
|
227
|
+
})] })] })]
|
|
228
|
+
}), (k || B) && /* @__PURE__ */ g(C, { open: o })] })
|
|
229
|
+
})]
|
|
230
|
+
}),
|
|
231
|
+
/* @__PURE__ */ _("div", {
|
|
232
|
+
className: "pco-org-avatar__dialog-actions",
|
|
233
|
+
children: [
|
|
234
|
+
l && z === "light" && /* @__PURE__ */ g(o, {
|
|
235
|
+
label: "Remove logo",
|
|
236
|
+
kind: "secondary-delete",
|
|
237
|
+
onClick: W,
|
|
238
|
+
loading: N,
|
|
239
|
+
disabled: N || j,
|
|
240
|
+
className: "pco-org-avatar__dialog-delete"
|
|
241
|
+
}),
|
|
242
|
+
l && z === "dark" && /* @__PURE__ */ g(o, {
|
|
243
|
+
label: "Use light mode logo",
|
|
244
|
+
kind: "secondary",
|
|
245
|
+
onClick: W,
|
|
246
|
+
loading: N,
|
|
247
|
+
disabled: N || j,
|
|
248
|
+
className: "pco-org-avatar__dialog-delete"
|
|
249
|
+
}),
|
|
250
|
+
/* @__PURE__ */ g(o, {
|
|
251
|
+
type: "button",
|
|
252
|
+
label: "Cancel",
|
|
253
|
+
onClick: () => R.current?.close(),
|
|
254
|
+
disabled: j || N
|
|
255
|
+
}),
|
|
256
|
+
/* @__PURE__ */ g(o, {
|
|
257
|
+
type: "submit",
|
|
258
|
+
label: "Update logo",
|
|
259
|
+
kind: "primary",
|
|
260
|
+
loading: j,
|
|
261
|
+
disabled: !k || j || N
|
|
262
|
+
})
|
|
263
|
+
]
|
|
264
|
+
})
|
|
265
|
+
]
|
|
266
|
+
})
|
|
267
|
+
}), document.body)] });
|
|
345
268
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
onAvatarUpdate: c,
|
|
382
|
-
fallbackAvatarUrl: i
|
|
383
|
-
}
|
|
384
|
-
)
|
|
385
|
-
] }),
|
|
386
|
-
w && i && !d && /* @__PURE__ */ r("div", { className: "pco-org-avatar-alert", children: [
|
|
387
|
-
/* @__PURE__ */ e(
|
|
388
|
-
"svg",
|
|
389
|
-
{
|
|
390
|
-
width: "16",
|
|
391
|
-
height: "16",
|
|
392
|
-
viewBox: "0 0 16 16",
|
|
393
|
-
className: "symbol",
|
|
394
|
-
"aria-hidden": "true",
|
|
395
|
-
children: /* @__PURE__ */ e("path", { d: Q })
|
|
396
|
-
}
|
|
397
|
-
),
|
|
398
|
-
/* @__PURE__ */ e("p", { children: "The same logo is being used for both light and dark modes." })
|
|
399
|
-
] })
|
|
400
|
-
] });
|
|
269
|
+
//#endregion
|
|
270
|
+
//#region src/organization_avatars.tsx
|
|
271
|
+
function T({ avatarUrl: e, darkModeAvatarUrl: t, orgName: n, onAvatarUpdate: i, pcoEnv: a, readOnly: o, showDarkModeAvatar: s = !1 }) {
|
|
272
|
+
let [c, u] = r(e), [d, f] = r(t), p = (e, t) => {
|
|
273
|
+
e === "avatar" ? (u(t), i?.("avatar", t)) : e === "dark_mode_avatar" && (f(t), i?.("dark_mode_avatar", t));
|
|
274
|
+
};
|
|
275
|
+
return /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ _("div", {
|
|
276
|
+
className: "pco-org-avatars",
|
|
277
|
+
children: [/* @__PURE__ */ g(w, {
|
|
278
|
+
avatarUrl: c,
|
|
279
|
+
organization: n,
|
|
280
|
+
mode: "avatar",
|
|
281
|
+
pcoEnv: a,
|
|
282
|
+
readOnly: o,
|
|
283
|
+
onAvatarUpdate: p
|
|
284
|
+
}), s && /* @__PURE__ */ g(w, {
|
|
285
|
+
avatarUrl: d,
|
|
286
|
+
organization: n,
|
|
287
|
+
mode: "dark_mode_avatar",
|
|
288
|
+
pcoEnv: a,
|
|
289
|
+
readOnly: o,
|
|
290
|
+
onAvatarUpdate: p,
|
|
291
|
+
fallbackAvatarUrl: c
|
|
292
|
+
})]
|
|
293
|
+
}), s && c && !d && /* @__PURE__ */ _("div", {
|
|
294
|
+
className: "pco-org-avatar-alert",
|
|
295
|
+
children: [/* @__PURE__ */ g("svg", {
|
|
296
|
+
width: "16",
|
|
297
|
+
height: "16",
|
|
298
|
+
viewBox: "0 0 16 16",
|
|
299
|
+
className: "symbol",
|
|
300
|
+
"aria-hidden": "true",
|
|
301
|
+
children: /* @__PURE__ */ g("path", { d: l })
|
|
302
|
+
}), /* @__PURE__ */ g("p", { children: "The same logo is being used for both light and dark modes." })]
|
|
303
|
+
})] });
|
|
401
304
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
};
|
|
305
|
+
//#endregion
|
|
306
|
+
export { T as OrganizationAvatars };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@testing-library/jest-dom/vitest";
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/organization-avatars",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Organization avatar upload components for Planning Center apps",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"packageManager": "yarn@
|
|
6
|
+
"packageManager": "yarn@4.16.0+sha512.5374c94eb4ef6aa8188fb112f20c1aa6569f248d676c5e576e1fd2a1a4d8d87a96df65d9dfe1c2a0252cbe38bda46cf18d955005b81b43cc7607a5c9d56fd2b6",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
8
8
|
"module": "./dist/index.js",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
"build": "rm -rf dist/ && vite build && tsc && cp src/organization_avatar.css dist/style.css",
|
|
25
25
|
"lint": "eslint src",
|
|
26
26
|
"lint:fix": "eslint src --fix",
|
|
27
|
-
"test": "
|
|
27
|
+
"test": "vitest run"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"clsx": "^2.1.1"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@planningcenter/icons": "^15.29.1",
|
|
34
|
-
"@planningcenter/sweetest-alert": "^1.0
|
|
35
|
-
"@planningcenter/tapestry": "^2.
|
|
34
|
+
"@planningcenter/sweetest-alert": "^1.2.0",
|
|
35
|
+
"@planningcenter/tapestry": "^3.2.1",
|
|
36
36
|
"@planningcenter/url": "^3.2.0",
|
|
37
37
|
"react": "^18.3.0",
|
|
38
38
|
"react-dom": "^18.3.0",
|
|
@@ -43,18 +43,25 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@planningcenter/icons": "^15.29.1",
|
|
46
|
-
"@planningcenter/sweetest-alert": "^1.0
|
|
47
|
-
"@planningcenter/tapestry": "^2.
|
|
46
|
+
"@planningcenter/sweetest-alert": "^1.2.0",
|
|
47
|
+
"@planningcenter/tapestry": "^3.2.1",
|
|
48
48
|
"@planningcenter/url": "^3.2.0",
|
|
49
|
+
"@testing-library/dom": "^10.4.1",
|
|
50
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
51
|
+
"@testing-library/react": "^16.3.2",
|
|
52
|
+
"@testing-library/user-event": "^14.6.1",
|
|
49
53
|
"@types/react": "^18.3.0",
|
|
50
54
|
"@types/react-dom": "^18.3.0",
|
|
51
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
52
|
-
"@typescript-eslint/parser": "^8.
|
|
53
|
-
"
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^8.58.1",
|
|
56
|
+
"@typescript-eslint/parser": "^8.58.1",
|
|
57
|
+
"@vitejs/plugin-react": "^6.0.1",
|
|
58
|
+
"eslint": "^10.2.0",
|
|
59
|
+
"jsdom": "^29.0.2",
|
|
54
60
|
"react": "^18.3.0",
|
|
55
61
|
"react-dom": "^18.3.0",
|
|
56
62
|
"react-dropzone": "^14.0.0",
|
|
57
63
|
"typescript": "^5.9.3",
|
|
58
|
-
"vite": "^
|
|
64
|
+
"vite": "^8.0.7",
|
|
65
|
+
"vitest": "^4.1.4"
|
|
59
66
|
}
|
|
60
67
|
}
|