-
Notifications
You must be signed in to change notification settings - Fork 87
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 #6298 from opengovsg/release_v6.49.0
build: release v6.49.0
- Loading branch information
Showing
37 changed files
with
502 additions
and
40 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
140 changes: 140 additions & 0 deletions
140
...rc/features/admin-form/settings/components/PaymentSettingsSection/BusinessInfoSection.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,140 @@ | ||
import { | ||
ChangeEventHandler, | ||
KeyboardEventHandler, | ||
useCallback, | ||
useRef, | ||
useState, | ||
} from 'react' | ||
import { FormControl } from '@chakra-ui/react' | ||
|
||
import { | ||
AgencyBase, | ||
FormResponseMode, | ||
StorageFormSettings, | ||
} from '~shared/types' | ||
|
||
import FormLabel from '~components/FormControl/FormLabel' | ||
import Input from '~components/Input' | ||
|
||
import { useAdminForm } from '~features/admin-form/common/queries' | ||
|
||
import { useMutateFormSettings } from '../../mutations' | ||
import { useAdminFormSettings } from '../../queries' | ||
|
||
interface BusinessFieldInputProps { | ||
initialValue: string | ||
handleMutation: (newAddress: string) => void | ||
placeholder: string | ||
} | ||
const BusinessFieldInput = ({ | ||
initialValue, | ||
handleMutation, | ||
placeholder, | ||
}: BusinessFieldInputProps): JSX.Element => { | ||
const [value, setValue] = useState(initialValue) | ||
|
||
const inputRef = useRef<HTMLInputElement>(null) | ||
|
||
const handleValueChange: ChangeEventHandler<HTMLInputElement> = useCallback( | ||
(e) => { | ||
setValue(e.target.value) | ||
}, | ||
[], | ||
) | ||
|
||
const handleBlur = useCallback(() => { | ||
if (value === initialValue) return | ||
const trimmedValue = value.trim() | ||
handleMutation(trimmedValue) | ||
setValue(trimmedValue) | ||
}, [handleMutation, value, initialValue]) | ||
|
||
const handleKeydown: KeyboardEventHandler<HTMLInputElement> = useCallback( | ||
(e) => { | ||
if (e.key === 'Enter') { | ||
e.preventDefault() | ||
inputRef.current?.blur() | ||
} | ||
}, | ||
[], | ||
) | ||
|
||
return ( | ||
<Input | ||
ref={inputRef} | ||
value={value} | ||
onChange={handleValueChange} | ||
onKeyDown={handleKeydown} | ||
onBlur={handleBlur} | ||
placeholder={placeholder} | ||
_placeholder={{ opacity: 1 }} | ||
/> | ||
) | ||
} | ||
|
||
const BusinessInfoBlock = ({ | ||
settings, | ||
agencyDefaults, | ||
}: { | ||
settings: StorageFormSettings | ||
agencyDefaults: AgencyBase['business'] | ||
}) => { | ||
const { mutateFormBusiness } = useMutateFormSettings() | ||
const handleAddressMutation = (newAddress: string) => { | ||
mutateFormBusiness.mutate({ address: newAddress }) | ||
} | ||
const handleGstRegNoMutation = (newGstRegNo: string) => { | ||
mutateFormBusiness.mutate({ gstRegNo: newGstRegNo }) | ||
} | ||
return ( | ||
<> | ||
<FormControl mb="2.5rem" isReadOnly={mutateFormBusiness.isLoading}> | ||
<FormLabel | ||
description="Leave empty to use your agency defaults." | ||
isRequired | ||
> | ||
GST Registration Number | ||
</FormLabel> | ||
<BusinessFieldInput | ||
placeholder={agencyDefaults?.gstRegNo || ''} | ||
initialValue={settings.business?.gstRegNo || ''} | ||
handleMutation={handleGstRegNoMutation} | ||
/> | ||
</FormControl> | ||
<FormControl mb="2.5rem" isReadOnly={mutateFormBusiness.isLoading}> | ||
<FormLabel | ||
description="Leave empty to use your agency defaults." | ||
isRequired | ||
> | ||
Business Address | ||
</FormLabel> | ||
<BusinessFieldInput | ||
placeholder={agencyDefaults?.address || ''} | ||
initialValue={settings.business?.address || ''} | ||
handleMutation={handleAddressMutation} | ||
/> | ||
</FormControl> | ||
</> | ||
) | ||
} | ||
|
||
export const BusinessInfoSection = () => { | ||
const { data: settings, isLoading } = useAdminFormSettings() | ||
const { data: adminSettings } = useAdminForm() | ||
|
||
if ( | ||
isLoading || | ||
!settings || | ||
settings.responseMode !== FormResponseMode.Encrypt || | ||
!adminSettings | ||
) { | ||
return <></> | ||
} | ||
|
||
return ( | ||
<BusinessInfoBlock | ||
settings={settings} | ||
agencyDefaults={adminSettings.admin.agency.business} | ||
/> | ||
) | ||
} |
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,13 @@ | ||
import { useQuery, UseQueryResult } from 'react-query' | ||
|
||
import { getEnabledFeatureFlags } from '~services/FeatureFlagService' | ||
|
||
export const featureFlagsKeys = { | ||
base: ['feature-flags'] as const, | ||
} | ||
|
||
// TODO: Add local caching system with interval based refresh | ||
// Refer to https://github.com/opengovsg/FormSG/pull/6286#discussion_r1190529370 | ||
export const useFeatureFlags = (): UseQueryResult<Set<string>> => { | ||
return useQuery(featureFlagsKeys.base, () => getEnabledFeatureFlags()) | ||
} |
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,7 @@ | ||
import { ApiService } from './ApiService' | ||
|
||
export const getEnabledFeatureFlags = async (): Promise<Set<string>> => { | ||
return ApiService.get<string[]>('/feature-flags/enabled').then( | ||
({ data }) => new Set(data), | ||
) | ||
} |
Oops, something went wrong.