Skip to content

Instantly share code, notes, and snippets.

@mamoru0217
Last active August 4, 2025 13:31
Show Gist options
  • Select an option

  • Save mamoru0217/55c403c498c1f3d6b4d8b67e3ff9ceb4 to your computer and use it in GitHub Desktop.

Select an option

Save mamoru0217/55c403c498c1f3d6b4d8b67e3ff9ceb4 to your computer and use it in GitHub Desktop.
タスク
  • サーバーから受け取ったsurveyFormのデータをstate上に適切に展開する状態管理。
  • surveyFormのUI上の見た目を変える状態管理。
  • 変化した状態をサーバーに送信する状態管理。

変更したい値 survey_form_title { [key]: string } survey_form_description: { [key]: string } survey_form_edition: string enable_scoring: boolean lock_version: number survey_form_sections: { survey_form_section_id: number, survey_form_section_title: { [key]: string }, survey_form_questions: [], is_default: true, display_order: 0, lock_version: 0, }

surveu

const defaultFormDetail =
    surveyFormDetail ||
    ({
      survey_form_id: 0,
      survey_form_title: {
        ja: '無題の調査フォーム',
        en: 'Untitled Survey Form',
      },
      survey_form_description: { ja: '', en: '' },
      survey_form_edition: 'Ver.1',
      enable_scoring: false,
      survey_form_sections: [
        {
          survey_form_section_id: 1,
          survey_form_section_title: {
            ja: 'デフォルトセクション',
            en: 'Default Section',
          },
          survey_form_questions: [
            {
              survey_form_id: 1,
              survey_form_question_id: 1,
              survey_form_question_title: {
                ja: 'サンプル質問',
                en: 'Sample Question',
              },
              survey_form_question_type: 'SurveyQuestionTypeSINGLE',
              creator_user: {
                email: 'hoge@example.com',
                user_id: 0,
                creator_user_name: 'System',
                join_status: 'JOINED',
              },
              is_required: true,
              is_remarks_enabled: false,
              display_order: 0,
              survey_form_question_answer_options: [
                {
                  survey_form_question_answer_option_id: 1,
                  survey_form_question_answer_option_label: {
                    ja: 'オプション1',
                    en: 'Option 1',
                  },
                  display_order: 0,
                  lock_version: 0,
                  // 必須フィールドのダミー値
                  business_account_id: 0,
                  created_at: new Date().toISOString(),
                  creator_user_id: 0,
                  survey_form_question_id: 1,
                  updated_at: new Date().toISOString(),
                } as SurveyFormQuestionAnswerOption,
                {
                  survey_form_question_answer_option_id: 2,
                  survey_form_question_answer_option_label: {
                    ja: 'オプション2',
                    en: 'Option 2',
                  },
                  display_order: 1,
                  lock_version: 0,
                  // 必須フィールドのダミー値
                  business_account_id: 0,
                  created_at: new Date().toISOString(),
                  creator_user_id: 0,
                  survey_form_question_id: 1,
                  updated_at: new Date().toISOString(),
                } as SurveyFormQuestionAnswerOption,
              ],
              // 必須フィールドのダミー値
              business_account_id: 0,
              created_at: new Date().toISOString(),
              creator_user_id: 0,
              lock_version: 0,
              survey_form_section_id: 1,
              updated_at: new Date().toISOString(),
            } as SurveyFormQuestion,
          ],
          is_default: true,
          display_order: 0,
          // 以下は必須フィールドのダミー値
          business_account_id: 0,
          created_at: new Date().toISOString(),
          creator_user_id: 0,
          lock_version: 0,
          survey_form_id: 0,
          updated_at: new Date().toISOString(),
        } as SurveyFormSection,
        {
          survey_form_section_id: 2,
          survey_form_section_title: {
            ja: '条件分岐セクション',
            en: 'Conditional Section',
          },
          survey_form_questions: [],
          is_default: false,
          display_order: 1,
          // 以下は必須フィールドのダミー値
          business_account_id: 0,
          created_at: new Date().toISOString(),
          creator_user_id: 0,
          lock_version: 0,
          survey_form_id: 0,
          updated_at: new Date().toISOString(),
        } as SurveyFormSection,
      ],
      survey_conditional_sections: [
        {
          survey_form_conditional_section_id: 1,
          survey_form_question_answer_option_id: 1,
          target_survey_form_section_id: 2,
          survey_form_question_answer_option_type:
            'SurveyQuestionAnswerOptionTypeSINGLE',
          business_account_id: 0,
          creator_user_id: 0,
          created_at: new Date().toISOString(),
          updated_at: new Date().toISOString(),
          lock_version: 0,
        } as SurveyFormConditionalSection,
      ],
      // SurveyForm必須フィールドのダミー値
      created_at: new Date().toISOString(),
      creator_user: {
        creator_user_name: 'System',
        creator_user_id: 0,
        email: 'system@example.com',
        join_status: 'JOINED',
        user_id: 0,
      },
      lock_version: 0,
      survey_form_status: 'SurveyFormStatusDRAFT',
      updated_at: new Date().toISOString(),
    } as SurveyFormDetail)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment