-
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.
feat(form-v2/react-to-angular/1): add switch to angular option (#4263)
* feat: add switch env endpoint for respondents * feat: add switchEnvMessage for respondents * feat: add AdminSwitchEnvMessage * fix: adjust styling * fix: adjust PublicSwitchEnvMessage margin * ref: hardcode angular in params * feat: add react-query env mutations * fix: amend cookie expiry date * fix: update cookie expiry * fix: navigate to old workspace page * fix: add window reload * fix: mutations * chore: add removal TODOs * fix: underline inline links
- Loading branch information
Showing
11 changed files
with
163 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// TODO #4279: Remove after React rollout is complete | ||
import { useMutation } from 'react-query' | ||
import { useNavigate } from 'react-router-dom' | ||
|
||
import { | ||
adminChooseEnvironment, | ||
publicChooseEnvironment, | ||
} from '~services/EnvService' | ||
|
||
export const useEnvMutations = () => { | ||
const navigate = useNavigate() | ||
|
||
const publicSwitchEnvMutation = useMutation(() => publicChooseEnvironment(), { | ||
onSuccess: () => window.location.reload(), | ||
}) | ||
|
||
const adminSwitchEnvMutation = useMutation(() => adminChooseEnvironment(), { | ||
onSuccess: () => { | ||
navigate('/#!/forms') | ||
window.location.reload() | ||
}, | ||
}) | ||
|
||
return { | ||
publicSwitchEnvMutation, | ||
adminSwitchEnvMutation, | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
frontend/src/features/public-form/components/PublicSwitchEnvMessage.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,23 @@ | ||
// TODO #4279: Remove after React rollout is complete | ||
import { Text } from '@chakra-ui/react' | ||
|
||
import Button from '~components/Button' | ||
import InlineMessage from '~components/InlineMessage' | ||
|
||
import { useEnvMutations } from '~features/env/mutations' | ||
|
||
export const PublicSwitchEnvMessage = (): JSX.Element => { | ||
const { publicSwitchEnvMutation } = useEnvMutations() | ||
|
||
return ( | ||
<InlineMessage variant="warning" mb="1.5rem" mt={{ base: '2rem', md: '0' }}> | ||
<Text> | ||
You’re filling this form on the new FormSG. If you have trouble | ||
submitting,{' '} | ||
<Button variant="link" onClick={() => publicSwitchEnvMutation.mutate}> | ||
<Text as="u">switch to the original one here.</Text> | ||
</Button> | ||
</Text> | ||
</InlineMessage> | ||
) | ||
} |
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
23 changes: 23 additions & 0 deletions
23
frontend/src/features/workspace/components/AdminSwitchEnvMessage.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,23 @@ | ||
// TODO #4279: Remove after React rollout is complete | ||
import { Text } from '@chakra-ui/react' | ||
|
||
import Button from '~components/Button' | ||
import InlineMessage from '~components/InlineMessage' | ||
|
||
import { useEnvMutations } from '~features/env/mutations' | ||
|
||
export const AdminSwitchEnvMessage = (): JSX.Element => { | ||
const { adminSwitchEnvMutation } = useEnvMutations() | ||
|
||
return ( | ||
<InlineMessage> | ||
<Text> | ||
Welcome to the new FormSG! You can still{' '} | ||
<Button variant="link" onClick={() => adminSwitchEnvMutation.mutate}> | ||
<Text as="u">switch to the original one,</Text> | ||
</Button>{' '} | ||
which is available until 28 May 2022. | ||
</Text> | ||
</InlineMessage> | ||
) | ||
} |
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,21 @@ | ||
// TODO #4279: Remove after React rollout is complete | ||
import { UiCookieValues } from '~shared/types' | ||
|
||
import { PUBLIC_FORMS_ENDPOINT } from '~features/public-form/PublicFormService' | ||
|
||
import { ApiService } from './ApiService' | ||
|
||
const ENV_ENDPOINT = '/environment' | ||
const ADMIN_ENDPOINT = '/admin' | ||
|
||
export const publicChooseEnvironment = async (): Promise<UiCookieValues> => { | ||
return ApiService.get( | ||
`${PUBLIC_FORMS_ENDPOINT}/${ENV_ENDPOINT}/${UiCookieValues.Angular}`, | ||
).then(({ data }) => data) | ||
} | ||
|
||
export const adminChooseEnvironment = async (): Promise<UiCookieValues> => { | ||
return ApiService.get( | ||
`${ADMIN_ENDPOINT}/${ENV_ENDPOINT}/${UiCookieValues.Angular}`, | ||
).then(({ data }) => data) | ||
} |
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