-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc86b80
commit 091f7cd
Showing
13 changed files
with
222 additions
and
82 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/plugins/strapi-plugin-internal-links/admin/src/api/locales.ts
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,36 @@ | ||
import { useQuery } from 'react-query'; | ||
|
||
import { useFetchClient } from '@strapi/helper-plugin'; | ||
|
||
const QUERY_KEY = 'locales'; | ||
|
||
export type Locale = { | ||
id: number; | ||
code: string; | ||
name?: string; | ||
isDefault?: boolean; | ||
createdAt?: string; | ||
updatedAt?: string; | ||
}; | ||
|
||
export const fetchLocales = async ({ fetchClient }: Record<string, any>): Promise<Locale[] | undefined> => { | ||
try { | ||
const { get } = fetchClient; | ||
const { data } = await get('i18n/locales'); | ||
|
||
return data; | ||
} catch { | ||
return undefined; | ||
} | ||
}; | ||
|
||
export const useGetLocales = (params: Record<string, any>) => { | ||
const fetchClient = useFetchClient(); | ||
|
||
return useQuery<Locale[] | undefined, Error>([QUERY_KEY], () => | ||
fetchLocales({ | ||
...params, | ||
fetchClient | ||
}) | ||
); | ||
}; |
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
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
42 changes: 42 additions & 0 deletions
42
...gins/strapi-plugin-internal-links/admin/src/components/form/page-select/locale-select.tsx
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,42 @@ | ||
import React from 'react'; | ||
import { SingleSelect, SingleSelectOption } from '@strapi/design-system'; | ||
|
||
import { IReactSelectValue } from '../../Combobox'; | ||
import { useGetLocales } from '../../../api/locales'; | ||
import S from './styles'; | ||
|
||
export interface LocaleReactSelectValue extends Omit<IReactSelectValue, 'initialSelected'> { | ||
id: number; | ||
name?: string; | ||
isDefault?: boolean; | ||
} | ||
|
||
interface Props { | ||
isDisabled?: boolean; | ||
onChange: (newValue?: string) => void; | ||
value?: string; | ||
isLoadingValue?: boolean; | ||
} | ||
|
||
export const LocaleSelect = ({ onChange, isDisabled, value, isLoadingValue }: Props) => { | ||
const { data: allLocales } = useGetLocales({}); | ||
|
||
const handleChange = (item?: string) => { | ||
onChange(item); | ||
}; | ||
|
||
return ( | ||
<S.LocaleSelectWrapper> | ||
<SingleSelect | ||
required | ||
disabled={isLoadingValue || isDisabled || (allLocales || [])?.length < 2} | ||
value={value} | ||
onChange={handleChange} | ||
> | ||
{(allLocales || []).map((l) => ( | ||
<SingleSelectOption value={l.code}>{l.code.toLocaleUpperCase()}</SingleSelectOption> | ||
))} | ||
</SingleSelect> | ||
</S.LocaleSelectWrapper> | ||
); | ||
}; |
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
Oops, something went wrong.