1import{r as N,j as e}from"./@radix-ui-1abab29d.js";import{h as D,i as G,A as F,j as ee,k as se,m as te,E as _,Q as q,R as z,a as W,o as K,F as Y,p as Z,q as E,r as R,v as M,x as I,w as O,y as V,J as ie,S as ae,T as re,z as C,U as ne}from"./index-b18b6ed8.js";import{a as le,D as de}from"./svgs-90e5c204.js";import{j as Q,e as H,h as $}from"./generated-types-a39aff67.js";import{aU as x,aV as U,aW as B,aR as J,aS as oe}from"./zod-7cb7d849.js";import"./react-query-6bd20b72.js";import"./date-fns-59b4ad06.js";import"./react-mixpanel-browser-4ee1dc3b.js";import"./recharts-62d881ba.js";(function(){try{var s=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},t=new Error().stack;t&&(s._sentryDebugIds=s._sentryDebugIds||{},s._sentryDebugIds[t]="aa7274b6-d2d5-4ea7-aca7-f7910af82bdd",s._sentryDebugIdIdentifier="sentry-dbid-aa7274b6-d2d5-4ea7-aca7-f7910af82bdd")}catch{}})();const ce=()=>{const s=D(),t=s==null?void 0:s.data,[i,n]=N.useState(void 0),a=c=>n(c),l=async()=>{t!=null&&t.id&&i&&await te(t.id,Q.Delivery,i),n(void 0)},u=()=>n(void 0),y=G((t==null?void 0:t.id)??"",Q.Delivery),[o,p]=N.useState(!1),w=()=>{l(),o&&p(!1)},r=N.useMemo(()=>(s==null?void 0:s.isLoading)||(s==null?void 0:s.isRefetching),[s]),j=y.data,v=t==null?void 0:t.delivery,S=v&&j&&!o,A=v&&j&&o;return e.jsxs(F,{title:"Delivery Hours",description:t!=null&&t.delivery?"Choose the hours your pantry is available for delivery orders.":"You have disabled delivery.",editMode:o,editable:(t==null?void 0:t.delivery)??!1,setEditMode:p,onSave:w,onCancel:u,className:"col-span-4",isLoading:r,children:[S?e.jsx(ee,{pantryHours:j}):e.jsx(e.Fragment,{}),A?e.jsx(se,{pantryId:(t==null?void 0:t.id)??"",pantryHours:j,update:a,hoursType:"delivery"}):e.jsx(e.Fragment,{})]})},ue=({pantryData:s,pantrySettings:t,pantryEntitySettings:i,pantryNetworks:n})=>{const[a,l]=N.useState(!1),[u,y]=N.useState(!1),o=W(),p=K(o==null?void 0:o.data,s);p||s.name.indexOf("Test Pantry");const w={},r=t.find(d=>d.key==H.DeliveryAvailableToPublic),j=r&&r.value?r.value=="true":!1,v={deliveryZips:s.deliveryZips??"",delivery:s.delivery??!1,availableToPublic:j},S={deliveryZips:x.array(x.string().min(1)),delivery:x.boolean(),availableToPublic:x.boolean()};for(const d of n){const g=`availableToNetwork_${d.id}`;S[g]=x.boolean();const b=i.find(k=>k.key==$.DeliveryAvailableToNetwork&&k.entityId==d.id);w[d.id]=b,v[g]=b&&b.value?b.value=="true":!1}const A=x.object(S),c=U({resolver:B(A),defaultValues:v}),f=c.control,h=c.watch();a?h.deliveryZips:s.deliveryZips;const m=async d=>{y(!0);const g={...s,...d,id:s.id??"",delivery:d.delivery,deliveryZips:d.deliveryZips};try{const b=await V(g);await ie(s.id??"",H.DeliveryAvailableToPublic,d.availableToPublic.toString());for(const P of n){const T=`availableToNetwork_${P.id}`;await ae(s.id??"",P.id??"",$.DeliveryAvailableToNetwork,d[T].toString())}const k=re(s.id??"");return C.invalidateQueries(k),l(!1),c.reset({...v,...d}),C.invalidateQueries(["pantry",s.slug]),b}catch(b){return console.error("update pantry request failed",b),!1}},L=c.formState.isSubmitting||!c.formState.isDirty||c.formState.disabled;return e.jsx(F,{title:"Delivery Availability",description:"Who has access to your Delivery Service",editMode:a,setEditMode:l,onSave:c.handleSubmit(m),isSubmitDisabled:L,isLoading:!1,className:"col-span-3",children:e.jsx("div",{className:"[&>div:last-child]:border-0 ",children:e.jsx(Y,{...c,children:e.jsxs("form",{onSubmit:c.handleSubmit(m),children:[e.jsx(Z,{editMode:a,editable:p||s.name.indexOf("Test Pantry")===0,label:"Public",value:(r==null?void 0:r.value)=="true"?"Yes":"No",displayClassName:"text-right",children:e.jsx(E,{control:f,name:"availableToPublic",render:({field:d})=>e.jsxs(R,{className:"fr justify-end",children:[e.jsx(M,{children:e.jsx(I,{value:d.value?"true":"false",onValueChange:g=>c.setValue("availableToPublic",g==="true",{shouldDirty:!0}),className:"w-20 my-0 text-end",editMode:a})}),e.jsx(O,{})]})})}),n.map(d=>{var P;const g=`availableToNetwork_${d.id}`,b=((P=w[d.id])==null?void 0:P.value)=="true"?"Yes":"No",k=""+d.name;return e.jsx(Z,{editMode:a,editable:p||s.name.indexOf("Test Pantry")===0,label:k,value:b,displayClassName:"text-right",children:e.jsx(E,{control:f,name:g,render:({field:T})=>e.jsxs(R,{className:"fr justify-end",children:[e.jsx(M,{children:e.jsx(I,{value:T.value?"true":"false",onValueChange:X=>c.setValue(g,X==="true",{shouldDirty:!0}),className:"w-20 my-0 text-end",editMode:a})}),e.jsx(O,{})]})})},g)})]})})})})};function me(){var l,u,y;const s=D(),t=_((l=s.data)==null?void 0:l.id),i=q((u=s.data)==null?void 0:u.id),n=z((y=s.data)==null?void 0:y.id);if(s.isLoading||s.isRefetching||n.isLoading||n.isRefetching||i.isLoading||i.isRefetching||t.isLoading||t.isRefetching)return e.jsx(F,{title:"Delivery Settings",description:"",editMode:!1,setEditMode:()=>{},onSave:()=>{},isSubmitDisabled:!0,isLoading:!0,className:"col-span-3"});if(s.data!==void 0){const o=s.data;
1return e.jsx(ue,{pantryData:o,pantrySettings:t.data??[],pantryNetworks:i.data??[],pantryEntitySettings:n.data??[]})}return e.jsx(e.Fragment,{})}const ye=({pantryData:s})=>{const[t,i]=N.useState(!1),[n,a]=N.useState(!1),l=W(),y=K(l==null?void 0:l.data,s)||s.name.indexOf("Test Pantry")===0,o={deliveryZips:s.deliveryZips??""},p={deliveryZips:x.array(x.string().min(1))},w=x.object(p),r=U({resolver:B(w),defaultValues:o}),j=r.watch(),v=t?j.deliveryZips:s.deliveryZips,S=async f=>{a(!0);const h={...s,id:s.id??"",deliveryZips:f.deliveryZips};try{const m=await V(h);return i(!1),r.reset({...o,...f}),C.invalidateQueries(["pantry",s.slug]),m}catch(m){return console.error("update pantry request failed",m),!1}},A=async(f,h)=>{const m=r.getValues().deliveryZips.filter(L=>L!==h);return m&&r.setValue("deliveryZips",m,{shouldDirty:!0}),f.preventDefault(),!1},c=r.formState.isSubmitting||!r.formState.isDirty||r.formState.disabled;return e.jsx(F,{title:"Delivery Settings",description:"Manage the delivery settings and zone for your pantry.",editMode:t,setEditMode:i,onSave:r.handleSubmit(S),isSubmitDisabled:c,isLoading:!1,className:"col-span-3",children:e.jsx("div",{className:"[&>div:last-child]:border-0 ",children:e.jsx(Y,{...r,children:e.jsx("form",{onSubmit:r.handleSubmit(S),children:e.jsx(Z,{editMode:t,editable:y,label:"Serviced Zip Codes","data-testid":"serviced-zip-codes",value:e.jsx("div",{className:"text-right leading-loose",children:e.jsx("div",{children:s.deliveryZips.filter(Boolean).join(", ")})}),children:e.jsx("table",{className:" [&>tbody>tr:last-child]:border-[1px] [&>tbody>tr:last-child]:border-f-input-gray [&>tbody>tr:last-child]:border-b-0 [&>tbody>tr:last-child]:border-r-0 [&>tbody>tr:last-child]:border-l-0 p-0 m-0",children:e.jsxs("tbody",{children:[v==null?void 0:v.map((f,h)=>e.jsxs("tr",{className:"gap-2 h-10",children:[e.jsx("td",{className:"px-[0.8215rem] ",children:t&&e.jsx("button",{className:"inline-block",onClick:m=>A(m,f),"data-testid":"delete-zip",children:e.jsx(le,{className:"flex justify-end flex-grow-0 w-3.5 h-3.5 place-self-start cursor-pointer"})})}),e.jsx("td",{className:"px-[0.8215rem] text-justify",children:e.jsx(ge,{editMode:t,index:h,zip:f,onChange:m=>r.setValue(`deliveryZips.${h}`,m,{shouldDirty:!0})})})]},"zip"+h)),e.jsx("tr",{className:"gap-2 h-10",children:e.jsx("td",{className:"px-[0.8215rem]",colSpan:2,children:e.jsx(fe,{editMode:t})})})]})})})})})})})};function ve(){var l,u,y;const s=D(),t=_((l=s.data)==null?void 0:l.id),i=q((u=s.data)==null?void 0:u.id),n=z((y=s.data)==null?void 0:y.id);if(s.isLoading||s.isRefetching||n.isLoading||n.isRefetching||i.isLoading||i.isRefetching||t.isLoading||t.isRefetching)return e.jsx(F,{title:"Delivery Settings",description:"",editMode:!1,setEditMode:()=>{},onSave:()=>{},isSubmitDisabled:!0,isLoading:!0,className:"col-span-3"});if(s.data!==void 0){const o=s.data;
1return e.jsx(ye,{pantryData:o})}return e.jsx(e.Fragment,{})}const fe=({editMode:s})=>{const t=J();return s?e.jsx("button",{type:"button",onClick:()=>{const i=t.getValues("deliveryZips").concat([""]);t.setValue("deliveryZips",i,{shouldDirty:!0})},className:"btn my-5 basis-72 text-sm tracking-custom2",children:"Add Zip"}):e.jsx("tr",{className:"border-none"})},ge=({zip:s,index:t,editMode:i=!1,onChange:n=()=>{}})=>{const a=J(),l=u=>{n(u)};return a.register(`roles.${t}`,{value:s}),e.jsx(oe,{...a,children:e.jsxs("div",{className:"py-2 aic text-left",children:[e.jsx("div",{className:`text-f-hyperlink text-base tracking-wide underline block my-[0.32rem] ${i?"hidden":""}`,children:s}),e.jsx("input",{type:"text","data-testid":`zip-${t}`,value:s,placeholder:"Enter 5-digit Zip Code",onChange:u=>l(u.target.value),className:i?"flex rounded-lg bg-whiteish border-[1px] p-2 mr-[0.87rem] text-base tracking-wide text-blackish placeholder:text-f-text-light-gray border-f-border-gray":"hidden"})]})})};function be(){const s=D(),t=s.isLoading||s.isRefetching,i=s.data;async function n(a){if(i){const l={...i,id:i.id??"",delivery:a};await V(l)}}if(t)return e.jsx(e.Fragment,{});if(s.data!==void 0){const a=s.data.delivery;return e.jsx("div",{className:"[&>div:last-child]:border-0 ",children:e.jsx(ne,{options:[{label:"Off",value:"false"},{label:"On",value:"true"}],value:a.toString(),onValueChange:()=>n(!a),className:"w-fit text-lg my-0 text-end [&>div]:p-1 [&>div]:px-[0.45rem] [&>div]:m-0 flex h-auto p-[0.25rem]"})})}return e.jsx(e.Fragment,{})}function Pe(){const t=D().data;return e.jsxs("div",{className:"font-roboto text-blackish mx-4",children:[e.jsxs("div",{className:"fr gap-24 aic w-full md:w-2/3",children:[e.jsxs("h1",{className:"sm:mt-0 lg:mt-6 ml-1 mb-8 text-5xl font-semibold tracking-wider ","data-testid":"admin-pantry-info-bumpdown",children:[e.jsx(de,{className:"inline-block mr-4"}),e.jsx("span",{className:" ",children:"Delivery Details"})]}),e.jsx(be,{})]}),(t==null?void 0:t.delivery)&&e.jsxs("div",{className:"grid md:grid-flow-row-dense md:grid-cols-6 gap-2 md:gap-8",children:[e.jsx(me,{}),e.jsx(ve,{}),e.jsx(ce,{})]})]})}export{Pe as default}; 2//# sourceMappingURL=AdminDeliveryDetails-9e7b09c2.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.