Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 27 additions & 12 deletions admin/src/components/LocationInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function Input({
const [autocompletionRequestOptions, setAutocompletionRequestOptions] =
useState(null);
const [textValue, setTextValue] = useState(
"" || (value !== "null" ? JSON.parse(value).description : "")
"" || (value !== "null" ? value?.description : "")
);

const { get } = useFetchClient();
Expand Down Expand Up @@ -118,13 +118,13 @@ export default function Input({
});
return;
}

let targetValue = null; // the value that will be sent to the server and saved in the database

let selectedPrediction = predictions.find(
(prediction) => prediction.place_id === val
);

if (selectedPrediction && selectedPrediction.place_id) {
setTextValue(selectedPrediction.description);
loader.load().then((google) => {
Expand Down Expand Up @@ -203,6 +203,21 @@ export default function Input({
},
});
};
function safeJsonParse(input) {
try {
// Check if the input is already an object
if (typeof input === 'object' && input !== null) {
return input; // Already parsed, return as-is
}

// Attempt to parse the input as JSON
return JSON.parse(input);
} catch (error) {
// Return null or handle parsing error
console.error('Failed to parse JSON:', error);
return null;
}
}

return (
<Flex direction="column" alignItems="start" gap={3}>
Expand All @@ -221,7 +236,7 @@ export default function Input({
onInputChange={(e) => handleInputChange(e)}
value={
value !== "null" && value
? JSON.parse(value).place_id
? safeJsonParse(value)?.place_id
: ""
}
textValue={textValue}
Expand Down Expand Up @@ -251,32 +266,32 @@ export default function Input({
style={{ display: "none" }}
>
{value !== "null" &&
JSON.parse(value).place_id === "custom_location"
? JSON.parse(value).description
safeJsonParse(value)?.place_id === "custom_location"
? safeJsonParse(value)?.description
: "Custom Location"}
</div>,
])
.concat([
<div
key="selected"
value={value !== "null" ? JSON.parse(value).place_id : ""}
value={value !== "null" ? safeJsonParse(value)?.place_id : ""}
style={{ display: "none" }}
>
{value !== "null" ? JSON.parse(value).description : ""}
{value !== "null" ? safeJsonParse(value)?.description : ""}
</div>,
])}
</Combobox>
)}
</Box>
{value !== "null" && JSON.parse(value).place_id === "custom_location" && (
{value !== "null" && safeJsonParse(value)?.place_id === "custom_location" && (
<Flex gap={2}>
<NumberInput
label="Latitude"
name="latitude"
placeholder="Ex. 43.123456"
disabled={disabled}
onValueChange={(e) => setCoordinates(e, "lat")}
value={value !== "null" ? JSON.parse(value).lat : null}
value={value !== "null" ? safeJsonParse(value)?.lat : null}
/>

<NumberInput
Expand All @@ -285,7 +300,7 @@ export default function Input({
placeholder="Ex. -79.123456"
disabled={disabled}
onValueChange={(e) => setCoordinates(e, "lng")}
value={value !== "null" ? JSON.parse(value).lng : null}
value={value !== "null" ? safeJsonParse(value)?.lng : null}
/>
</Flex>
)}
Expand All @@ -295,4 +310,4 @@ export default function Input({

Input.defaultProps = {
value: "null",
};
};
3 changes: 2 additions & 1 deletion admin/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const name = pluginPkg.strapi.name;

export default {
register(app) {

app.registerPlugin({
id: pluginId,
initializer: Initializer,
Expand Down Expand Up @@ -58,4 +59,4 @@ export default {

return Promise.resolve(importedTrads);
},
};
};
1 change: 1 addition & 0 deletions admin/src/translations/he.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading