Skip to content

Commit

Permalink
fix(form): Correct locales data fetching.
Browse files Browse the repository at this point in the history
  • Loading branch information
vinci1it2000 committed Sep 25, 2024
1 parent f8017de commit b1596b4
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 58 deletions.
10 changes: 7 additions & 3 deletions schedula/utils/form/react/src/core/components/Static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import DOMPurify from 'dompurify';

export default function Static({children, render, sanitize, url, ...props}) {
const [html, setHTML] = useState(null)

const {formContext} = render
const {form} = formContext
useEffect(() => {
if (url) {
fetch(url).then(r => r.text()).then(text => {
form.postData({
url,
method: 'GET'
}, ({data: text}) => {
if (sanitize)
text = DOMPurify.sanitize(text, sanitize)
setHTML(text)
Expand All @@ -17,7 +21,7 @@ export default function Static({children, render, sanitize, url, ...props}) {
text = DOMPurify.sanitize(text, sanitize)
setHTML(text)
}
}, [url, children, sanitize])
}, [url, children, sanitize, form])

return html ?
<div {...props} dangerouslySetInnerHTML={{__html: html}}/> : null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function Stripe(
setClientSecret(clientSecret)
})
}
}, [])
})
const onComplete = useCallback(() => {
form.postData({
url: `${urlCreateCheckoutStatus}/${sessionId}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const StripePortal = forwardRef((
} else if (popup) {
popup.close()
}
}, [open, urlPortalSession, form, language, user_id])
}, [open, urlPortalSession, form, language, user_id, height, width, top, bottom, left, right])
useEffect(() => {
if (popup) {
const bringToFront = setInterval(() => {
Expand Down
102 changes: 49 additions & 53 deletions schedula/utils/form/react/src/themes/antd/components/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,15 @@ const App = (
const [languageOptions, setLanguageOptions] = useState(languages !== true ? languages : null);
useEffect(() => {
if (languages === true)
fetch('/locales', {
headers: {
'Content-Type': 'application/json',
'Content-Encoding': 'gzip',
'Accept-Encoding': 'gzip'
}
}).then(v => v.json()).then((v) => {
setLanguageOptions(v)
}).catch((error) => {
form.postData({
url: '/locales',
method: 'GET'
}, ({data}) => {
setLanguageOptions(data)
}, () => {
setLanguageOptions(null)
form.props.notify({message: error})
})
}, [languages, form.props]);
}, [languages, form]);
const {errors, debugUrl} = form.state
const [openErrors, setOpenErrors] = useState(false);
const [openDebug, setOpenDebug] = useState(!!debugUrl);
Expand Down Expand Up @@ -230,51 +226,51 @@ const App = (
padding: 0,
display: "flex",
}}>
<div key={'logo'} style={{
height: "100%",
textAlign: 'center',
lineHeight: 'normal'
}}>{logo ? createLayoutElement({
key: 'logo', layout: logo, render, isArray: false
}) : null}</div>
{_items.length ? <Menu
key={'left-menu'}
theme={theme}
mode="horizontal"
style={{flex: "auto", minWidth: 0}}
selectedKeys={selectedKeys}
items={_items}
onSelect={({key}) => {
setSelectedKeys([key])
}}
{...props}
/> : <div style={{flex: "auto", minWidth: 0}}/>}
{currentDataId || urlContact || languages || userProps ?
<Flex key={'right-element'}
style={{
paddingLeft: '16px',
paddingRight: '16px',
cursor: 'pointer'
}}
gap="middle">
{currentDataId ? <Typography.Text keyboard>
# {currentDataId.id} - {currentDataId.name}
</Typography.Text> : null}
{urlContact ? <ContactNav
<div key={'logo'} style={{
height: "100%",
textAlign: 'center',
lineHeight: 'normal'
}}>{logo ? createLayoutElement({
key: 'logo', layout: logo, render, isArray: false
}) : null}</div>
{_items.length ? <Menu
key={'left-menu'}
theme={theme}
mode="horizontal"
style={{flex: "auto", minWidth: 0}}
selectedKeys={selectedKeys}
items={_items}
onSelect={({key}) => {
setSelectedKeys([key])
}}
{...props}
/> : <div style={{flex: "auto", minWidth: 0}}/>}
{currentDataId || urlContact || languages || userProps ?
<Flex key={'right-element'}
style={{
paddingLeft: '16px',
paddingRight: '16px',
cursor: 'pointer'
}}
gap="middle">
{currentDataId ? <Typography.Text keyboard>
# {currentDataId.id} - {currentDataId.name}
</Typography.Text> : null}
{urlContact ? <ContactNav
form={form}
formContext={formContext}
containerRef={mainLayout}
urlContact={urlContact}/> : null}
{languageOptions ? <LanguageNav
form={form}
languages={languageOptions}/> : null}
{userProps ?
<UserNav
form={form}
formContext={formContext}
containerRef={mainLayout}
urlContact={urlContact}/> : null}
{languageOptions ? <LanguageNav
form={form}
languages={languageOptions}/> : null}
{userProps ?
<UserNav
form={form}
formContext={formContext}
containerRef={mainLayout}
{...userProps}/> : null}
</Flex> : null}
{...userProps}/> : null}
</Flex> : null}
</Header> : null}
<Layout ref={mainLayout} style={{
position: 'relative'
Expand Down
2 changes: 2 additions & 0 deletions schedula/utils/form/server/locale/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from flask import (
jsonify, current_app, request, session, Blueprint, send_from_directory
)

bp = Blueprint('locales', __name__)


Expand All @@ -43,6 +44,7 @@ def locales(language, namespace):
raise NotFound()


@bp.route('', methods=['GET'])
@bp.route('/', methods=['GET'])
def get_locales():
return jsonify(current_app.config.get('BABEL_LANGUAGES'))
Expand Down

0 comments on commit b1596b4

Please sign in to comment.