-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #336 from EscolaLMS/feature/additional-fields-tran…
…slations-admin additional fields translations from admin
- Loading branch information
Showing
4 changed files
with
153 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { API } from "@escolalms/sdk/lib"; | ||
import { useCallback } from "react"; | ||
import { useTranslation } from "react-i18next"; // assuming you are using react-i18next for translations | ||
|
||
const useAdditionalField = () => { | ||
const { i18n } = useTranslation(); | ||
|
||
const additionalFieldTranslations = useCallback( | ||
(fieldMeta: API.Metadata) => { | ||
//@ts-ignore | ||
Check warning on line 10 in src/hooks/useAdditionalFieldsTranslations.tsx GitHub Actions / eslint (20.x)
Check warning on line 10 in src/hooks/useAdditionalFieldsTranslations.tsx GitHub Actions / build
|
||
const translations = fieldMeta?.extra?.[0]?.translations; | ||
if (translations && typeof translations === "object") { | ||
return translations[i18n.language]; | ||
} else { | ||
return false; | ||
} | ||
}, | ||
[i18n.language] | ||
); | ||
|
||
const filter = useCallback( | ||
(fieldMeta: API.Metadata, keyName = "register") => { | ||
return ( | ||
Array.isArray(fieldMeta.extra) && | ||
fieldMeta.extra.filter( | ||
(item: Record<string, string | number | boolean> | null) => { | ||
return item && item[keyName]; | ||
} | ||
) | ||
); | ||
}, | ||
[] | ||
); | ||
|
||
return { | ||
getFieldTranslations: additionalFieldTranslations, | ||
filterByKey: filter, | ||
}; | ||
}; | ||
|
||
export default useAdditionalField; |